From 8a72baab0958f09d603e4dc78fdc0e4cb656f6d6 Mon Sep 17 00:00:00 2001 From: Denis Anikin Date: Mon, 9 Oct 2023 22:06:24 +0300 Subject: [PATCH] Improved typing --- scripts/__main__.py | 14 +++++++------- whole_app/dictionaries/file.py | 8 +++++--- whole_app/spell.py | 1 - 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/scripts/__main__.py b/scripts/__main__.py index 997e7d6..439bc58 100755 --- a/scripts/__main__.py +++ b/scripts/__main__.py @@ -9,12 +9,12 @@ from ._helpers import parse_last_git_tag, replace_tag_in_readme -PARENT_DIR: pathlib.Path = pathlib.Path(__file__).parent.parent -README_PATH: pathlib.Path = PARENT_DIR / "README.md" +PARENT_DIR: typing.Final = pathlib.Path(__file__).parent.parent +README_PATH: typing.Final = PARENT_DIR / "README.md" def _update_dockerhub_readme() -> None: - new_content: str = re.sub( + new_content = re.sub( r"\#\# Development.*", r"", README_PATH.read_text(), @@ -28,7 +28,7 @@ def _update_readme() -> None: from whole_app.settings import SETTINGS new_content: str = README_PATH.read_text() - settings_schema: dict[str, typing.Any] = SETTINGS.schema()["properties"] + settings_schema: typing.Final[dict[str, typing.Any]] = SETTINGS.schema()["properties"] pack_of_readme_lines: list[str] = [] for props in settings_schema.values(): settings_env_key: str = props["env_names"].pop().upper() @@ -62,9 +62,9 @@ def _update_readme() -> None: if __name__ == "__main__": sys.path.append(str(PARENT_DIR.resolve())) - parser: argparse.ArgumentParser = argparse.ArgumentParser() - parser.add_argument("action") - arguments_list: argparse.Namespace = parser.parse_args() + parser_obj: typing.Final = argparse.ArgumentParser() + parser_obj.add_argument("action") + arguments_list: argparse.Namespace = parser_obj.parse_args() match arguments_list.action: case "update-dockerhub-readme": _update_dockerhub_readme() diff --git a/whole_app/dictionaries/file.py b/whole_app/dictionaries/file.py index f91ee66..975606c 100644 --- a/whole_app/dictionaries/file.py +++ b/whole_app/dictionaries/file.py @@ -1,3 +1,5 @@ +import typing + import aiopath from whole_app.settings import SETTINGS @@ -22,14 +24,14 @@ async def _store_lines(self: "FileProvider", lines: list[str]) -> None: async def save_record(self: "FileProvider", exception_word: str) -> None: await self._user_dict_path.touch() - clean_word: str = exception_word.strip().lower() - file_content: list[str] = await self.fetch_records() + clean_word: typing.Final = exception_word.strip().lower() + file_content = await self.fetch_records() if clean_word not in file_content: file_content.append(clean_word) await self._store_lines(file_content) async def remove_record(self: "FileProvider", exception_word: str) -> None: - file_content: list[str] = await self.fetch_records() + file_content = await self.fetch_records() if exception_word in file_content: file_content.remove(exception_word) await self._store_lines(file_content) diff --git a/whole_app/spell.py b/whole_app/spell.py index 77e87ed..ee66460 100644 --- a/whole_app/spell.py +++ b/whole_app/spell.py @@ -14,7 +14,6 @@ class SpellCheckService: __slots__ = ("_input_text", "_spellcheck_engine", "_exclusion_words") - _input_text: str _spellcheck_engine: SpellChecker _exclusion_words: list[str]