diff --git a/pyglossary/entry.py b/pyglossary/entry.py index 92136f9f6..58559a306 100644 --- a/pyglossary/entry.py +++ b/pyglossary/entry.py @@ -247,6 +247,9 @@ def __init__( self._defiFormat = defiFormat self._byteProgress = byteProgress # tuple[int, int] | None + def getFileName(self) -> str: + return "" + def __repr__(self) -> str: return ( f"Entry({self._word!r}, {self._defi!r}, " diff --git a/pyglossary/entry_merge.py b/pyglossary/entry_merge.py index 2d397f80c..ebf702104 100644 --- a/pyglossary/entry_merge.py +++ b/pyglossary/entry_merge.py @@ -40,7 +40,7 @@ def mergeHtmlEntriesWithSameHeadword( entryIter: Iterator[EntryType], ) -> Iterator[EntryType]: try: - last: EntryType = next(entryIter) + last: EntryType | None = next(entryIter) except StopIteration: return last.detectDefiFormat() @@ -63,7 +63,7 @@ def mergeHtmlEntriesWithSameHeadword( defi = getHtmlDefi(last) + "\n
\n" + getHtmlDefi(entry) - last = Entry( + last = Entry( # pyright: ignore entry.l_word[0], defi, defiFormat="h", @@ -77,7 +77,7 @@ def mergePlaintextEntriesWithSameHeadword( entryIter: Iterator[EntryType], ) -> Iterator[EntryType]: try: - last: EntryType = next(entryIter) + last: EntryType | None = next(entryIter) except StopIteration: return for entry in entryIter: @@ -105,7 +105,7 @@ def mergePlaintextEntriesWithSameHeadword( + entry.defi ) - last = Entry( + last = Entry( # pyright: ignore entry.l_word[0], defi, defiFormat="m", diff --git a/pyglossary/glossary.py b/pyglossary/glossary.py index 28ec2f86d..03482a04c 100644 --- a/pyglossary/glossary.py +++ b/pyglossary/glossary.py @@ -31,6 +31,7 @@ from typing import Any from .glossary_types import EntryType + from .plugin_manager import DetectedFormat __all__ = ["Glossary"] @@ -138,7 +139,7 @@ def sortWords( self._iter = self._loadedEntryGen() @classmethod - def detectInputFormat(cls, *args, **kwargs): + def detectInputFormat(cls, *args, **kwargs) -> DetectedFormat | None: # pyright: ignore[reportIncompatibleMethodOverride] try: return GlossaryCommon.detectInputFormat(*args, **kwargs) except Error as e: @@ -146,7 +147,7 @@ def detectInputFormat(cls, *args, **kwargs): return None @classmethod - def detectOutputFormat(cls, *args, **kwargs): + def detectOutputFormat(cls, *args, **kwargs) -> DetectedFormat | None: # pyright: ignore[reportIncompatibleMethodOverride] try: return GlossaryCommon.detectOutputFormat(*args, **kwargs) except Error as e: diff --git a/pyglossary/glossary_v2.py b/pyglossary/glossary_v2.py index 4bb9b7a4b..19fd0873c 100644 --- a/pyglossary/glossary_v2.py +++ b/pyglossary/glossary_v2.py @@ -276,11 +276,11 @@ def _entryFromRaw(self, rawEntryArg: RawEntryType) -> EntryType: fname = word if isinstance(fname, list): fname = fname[0] # NESTED 4 - return DataEntry(fname, tmpPath=defi) + return DataEntry(fname, tmpPath=defi) # pyright: ignore[reportReturnType] else: defiFormat = self._defaultDefiFormat - return Entry(word, defi, defiFormat=defiFormat) + return Entry(word, defi, defiFormat=defiFormat) # pyright: ignore[reportReturnType] @property def rawEntryCompress(self) -> bool: @@ -359,7 +359,7 @@ def stripFullHtml( if name in self._entryFiltersName: return self._entryFilters.append( - StripFullHtml( + StripFullHtml( # pyright: ignore[reportArgumentType] cast(GlossaryType, self), errorHandler=errorHandler, ), @@ -401,6 +401,7 @@ def mergeEntriesWithSameHeadwordPlaintext(self): """ from pyglossary.entry_merge import mergePlaintextEntriesWithSameHeadword + assert self._iter self._iter = mergePlaintextEntriesWithSameHeadword(self._iter) def __str__(self) -> str: @@ -418,13 +419,14 @@ def _loadedEntryGen(self) -> Iterator[EntryType]: filters = self._entryFiltersExtra if self.progressbar: - filters.append(ShowProgressBar(cast(GlossaryExtendedType, self))) + filters.append(ShowProgressBar(cast(GlossaryExtendedType, self))) # pyright: ignore[reportArgumentType] self.progressInit("Writing") for _entry in self._data: entry = _entry for f in filters: entry = f.run(entry) + assert entry yield entry self.progressEnd() @@ -615,10 +617,10 @@ def newEntry( def newDataEntry(self, fname: str, data: bytes) -> EntryType: if self._readers: - return DataEntry(fname, data) + return DataEntry(fname, data) # pyright: ignore[reportReturnType] if self._tmpDataDir: - return DataEntry( + return DataEntry( # pyright: ignore[reportReturnType] fname, data, tmpPath=join(self._tmpDataDir, fname.replace("/", "_")), @@ -627,7 +629,7 @@ def newDataEntry(self, fname: str, data: bytes) -> EntryType: tmpDir = join(cacheDir, "tmp") os.makedirs(tmpDir, mode=0o700, exist_ok=True) self._cleanupPathList.add(tmpDir) - return DataEntry( + return DataEntry( # pyright: ignore[reportReturnType] fname, data, tmpPath=join(tmpDir, uuid1().hex), @@ -969,7 +971,7 @@ def _switchToSQLite( log.info(f"Removing and re-creating {sq_fpath!r}") os.remove(sq_fpath) - self._data = SqEntryList( + self._data = SqEntryList( # pyright: ignore[reportAttributeAccessIssue] entryToRaw=self._entryToRaw, entryFromRaw=self._entryFromRaw, filename=sq_fpath, @@ -1122,7 +1124,7 @@ def _convertPrepare( args: ConvertArgs, outputFilename: str = "", outputFormat: str = "", - ) -> bool | None: + ) -> bool: if isdir(outputFilename) and os.listdir(outputFilename): raise Error( f"Directory already exists and not empty: {relpath(outputFilename)}", @@ -1188,8 +1190,6 @@ def convertV2(self, args: ConvertArgs) -> str: outputFilename=outputFilename, outputFormat=outputFormat, ) - if sort is None: - return None if args.infoOverride: for key, value in args.infoOverride.items(): diff --git a/pyproject.toml b/pyproject.toml index 371c71827..e3842057d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,9 +4,7 @@ indent-style = "tab" skip-magic-trailing-comma = false line-ending = "lf" docstring-code-format = false -exclude = [ - "pyglossary/plugin_lib/ripemd128.py", -] +exclude = ["pyglossary/plugin_lib/ripemd128.py"] [tool.ruff] line-length = 88 @@ -103,7 +101,7 @@ select = [ "RUF", # Ruff-specific rules ] ignore = [ - "RUF039", # First argument to `re.compile()` is not raw string + "RUF039", # First argument to `re.compile()` is not raw string "FURB189", # FURB189 Subclassing `dict` can be error prone, use `collections.UserDict` instead # FURB189 Subclassing `str` can be error prone, use `collections.UserStr` instead @@ -175,7 +173,7 @@ mccabe.max-complexity = 13 # Unlike Flake8, default to a complexity level of 10. [tool.ruff.lint.per-file-ignores] "*_types.py" = [ - "TC003", # Move standard library import `...` into a type-checking block + "TC003", # Move standard library import `...` into a type-checking block ] "pyglossary/plugins/**/*.py" = [ "PLR0904", # Too many public methods @@ -238,7 +236,6 @@ mccabe.max-complexity = 13 # Unlike Flake8, default to a complexity level of 10. "doc/lib-examples/*.py" = ["ANN", "INP"] - [tool.mypy] exclude = [ # '.*/plugin_lib/.*', @@ -350,6 +347,42 @@ verbose = false [tool.import-analyzer] exclude = ["pyglossary/ui/wcwidth/", "build/"] +[tool.pyright] +pythonVersion = "3.10" +pythonPlatform = "Linux" +reportMissingImports = "error" +reportMissingTypeStubs = false +exclude = [ + "pyglossary/slob.py", + "setup.py", + "whitelist.py", # for vulture + # "pyglossary/ui/gtk4_utils/*", + # "pyglossary/ui/gtk3_utils/*", + "pyglossary/plugins/babylon_bgl/bgl_gzip.py", + "pyglossary/plugins/testformat.py", + # "pyglossary/plugin_lib/*", + "pyglossary/ui/gtk*_utils/__init__.py", + "pyglossary/ui/ui_qt.py", + "pyglossary/ui/progressbar/", + "pyglossary/reverse.py", + "wcwidth*", + ".direnv", + ".eggs", + ".git", + ".mypy_cache", + ".nox", + ".pants.d", + ".ruff_cache", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "venv", +] + # [project] # name = "pyglossary"