Skip to content

Commit

Permalink
WIP: fix or ignore some pyright errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Nov 24, 2024
1 parent ae8e072 commit 422479f
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 19 deletions.
5 changes: 3 additions & 2 deletions pyglossary/glossary.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
from typing import Any

from .glossary_types import EntryType
from .plugin_manager import DetectedFormat

__all__ = ["Glossary"]

Expand Down Expand Up @@ -138,15 +139,15 @@ 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:
log.critical(str(e))
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:
Expand Down
22 changes: 11 additions & 11 deletions pyglossary/glossary_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
),
Expand Down Expand Up @@ -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:
Expand All @@ -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()

Expand Down Expand Up @@ -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("/", "_")),
Expand All @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)}",
Expand Down Expand Up @@ -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():
Expand Down
45 changes: 39 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/.*',
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 422479f

Please sign in to comment.