From 6ca99022f894474c16a244d15b821ebacb75627f Mon Sep 17 00:00:00 2001 From: Saeed Rasooli Date: Sun, 30 Jun 2024 22:10:19 +0330 Subject: [PATCH] fix some mypy errors --- pyglossary/glossary_v2.py | 6 +++--- pyglossary/plugins/abc_medical_notes.py | 4 ++-- pyglossary/plugins/almaany.py | 3 ++- pyglossary/plugins/crawler_dir.py | 2 +- pyglossary/plugins/dict_cc.py | 3 ++- pyglossary/plugins/dict_cc_split.py | 3 ++- pyglossary/plugins/digitalnk.py | 3 ++- pyglossary/plugins/stardict_textual.py | 2 +- pyglossary/plugins/tabfile.py | 1 + 9 files changed, 16 insertions(+), 11 deletions(-) diff --git a/pyglossary/glossary_v2.py b/pyglossary/glossary_v2.py index 112d2c500..26504a7c1 100644 --- a/pyglossary/glossary_v2.py +++ b/pyglossary/glossary_v2.py @@ -184,7 +184,7 @@ def __init__( self._sqlite = False self._rawEntryCompress = False self._cleanupPathList: "set[str]" = set() - self._readOptions = None + self._readOptions: dict[str, Any] | None = None self.clear() @@ -572,7 +572,7 @@ def newEntry( byteProgress=byteProgress, ) - def newDataEntry(self, fname: str, data: bytes) -> "DataEntry": + def newDataEntry(self, fname: str, data: bytes) -> "EntryType": import uuid if self._readers: @@ -839,7 +839,7 @@ def _writeEntries( if self._config.get("save_info_json", False): from pyglossary.info_writer import InfoWriter - infoWriter = InfoWriter(self) + infoWriter = InfoWriter(cast(GlossaryType, self)) filenameNoExt, _, _, _ = splitFilenameExt(filename) infoWriter.open(f"{filenameNoExt}.info") genList.append(infoWriter.write()) diff --git a/pyglossary/plugins/abc_medical_notes.py b/pyglossary/plugins/abc_medical_notes.py index 8262eb99d..eaadf995e 100644 --- a/pyglossary/plugins/abc_medical_notes.py +++ b/pyglossary/plugins/abc_medical_notes.py @@ -8,7 +8,7 @@ from collections.abc import Iterator from pyglossary.glossary_types import EntryType, GlossaryType - + from pyglossary.option import Option __all__ = [ "Reader", @@ -39,7 +39,7 @@ _url, "ABC Medical Notes 2021 - Google Play", ) -optionsProp = {} +optionsProp: "dict[str, Option]" = {} class Reader: diff --git a/pyglossary/plugins/almaany.py b/pyglossary/plugins/almaany.py index 603390e91..79346da31 100644 --- a/pyglossary/plugins/almaany.py +++ b/pyglossary/plugins/almaany.py @@ -8,6 +8,7 @@ from collections.abc import Iterator from pyglossary.glossary_types import EntryType, GlossaryType + from pyglossary.option import Option __all__ = [ "Reader", @@ -37,7 +38,7 @@ "https://play.google.com/store/apps/details?id=com.almaany.arar", "Almaany.com Arabic Dictionary - Google Play", ) -optionsProp = {} +optionsProp: "dict[str, Option]" = {} class Reader: diff --git a/pyglossary/plugins/crawler_dir.py b/pyglossary/plugins/crawler_dir.py index e8c6a17df..74168126e 100644 --- a/pyglossary/plugins/crawler_dir.py +++ b/pyglossary/plugins/crawler_dir.py @@ -180,7 +180,7 @@ def _readDir( self, dpath: str, exclude: "set[str] | None", - ) -> "Generator[None, EntryType, None]": + ) -> "Generator[EntryType, None, None]": children = listdir(dpath) if exclude: children = [name for name in children if name not in exclude] diff --git a/pyglossary/plugins/dict_cc.py b/pyglossary/plugins/dict_cc.py index 651cc4629..ce20d73e3 100644 --- a/pyglossary/plugins/dict_cc.py +++ b/pyglossary/plugins/dict_cc.py @@ -10,6 +10,7 @@ from pyglossary.glossary_types import EntryType, GlossaryType from pyglossary.lxml_types import Element, T_htmlfile + from pyglossary.option import Option from pyglossary.core import log @@ -42,7 +43,7 @@ "https://play.google.com/store/apps/details?id=cc.dict.dictcc", "dict.cc dictionary - Google Play", ) -optionsProp = {} +optionsProp: "dict[str, Option]" = {} class Reader: diff --git a/pyglossary/plugins/dict_cc_split.py b/pyglossary/plugins/dict_cc_split.py index b3cfaacf8..c6fa4af77 100644 --- a/pyglossary/plugins/dict_cc_split.py +++ b/pyglossary/plugins/dict_cc_split.py @@ -8,6 +8,7 @@ import sqlite3 from pyglossary.glossary_types import EntryType, GlossaryType + from pyglossary.option import Option from pyglossary.core import log @@ -39,7 +40,7 @@ "https://play.google.com/store/apps/details?id=cc.dict.dictcc", "dict.cc dictionary - Google Play", ) -optionsProp = {} +optionsProp: "dict[str, Option]" = {} class Reader: diff --git a/pyglossary/plugins/digitalnk.py b/pyglossary/plugins/digitalnk.py index b2fd49d51..582047bd7 100644 --- a/pyglossary/plugins/digitalnk.py +++ b/pyglossary/plugins/digitalnk.py @@ -8,6 +8,7 @@ import sqlite3 from pyglossary.glossary_types import EntryType, GlossaryType + from pyglossary.option import Option __all__ = [ "Reader", @@ -37,7 +38,7 @@ "https://github.com/digitalprk/dicrs", "@digitalprk/dicrs", ) -optionsProp = {} +optionsProp: "dict[str, Option]" = {} class Reader: diff --git a/pyglossary/plugins/stardict_textual.py b/pyglossary/plugins/stardict_textual.py index 042c0f63d..199160644 100644 --- a/pyglossary/plugins/stardict_textual.py +++ b/pyglossary/plugins/stardict_textual.py @@ -172,7 +172,7 @@ def renderDefiList( if len(defisWithFormat) == 1: return defisWithFormat[0] - defiFormatSet = set() + defiFormatSet: set[str] = set() defiFormatSet.update(_type for _, _type in defisWithFormat) if len(defiFormatSet) == 1: diff --git a/pyglossary/plugins/tabfile.py b/pyglossary/plugins/tabfile.py index 6bfccf858..3dee0269d 100644 --- a/pyglossary/plugins/tabfile.py +++ b/pyglossary/plugins/tabfile.py @@ -60,6 +60,7 @@ def open(self, filename: str) -> "Iterator[tuple[int, int]] | None": if isdir(resDir): self._resDir = resDir self._resFileNames = os.listdir(self._resDir) + return None # noqa: B901 because of mypy def __iter__(self) -> "Iterator[EntryType | None]": yield from TextGlossaryReader.__iter__(self)