Skip to content

Commit

Permalink
check all ruff linters, fix some, ignore some
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Feb 22, 2024
1 parent 47f2325 commit 4fb9f78
Show file tree
Hide file tree
Showing 65 changed files with 367 additions and 309 deletions.
16 changes: 8 additions & 8 deletions pyglossary/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@


__all__ = [
"StdLogHandler",
"TRACE",
"VERSION",
"StdLogHandler",
"appResDir",
"cacheDir",
"checkCreateConfDir",
Expand Down Expand Up @@ -76,7 +76,7 @@ def trace(log: logging.Logger, msg: str) -> None:


class _Formatter(logging.Formatter):
def __init__(self, *args, **kwargs) -> None: # noqa: ANN
def __init__(self, *args, **kwargs) -> None: # noqa: ANN101
logging.Formatter.__init__(self, *args, **kwargs)
self.fill: "Callable[[str], str] | None" = None

Expand All @@ -100,17 +100,17 @@ class _MyLogger(logging.Logger):
TRACE,
logging.NOTSET,
)
levelNamesCap = [
levelNamesCap = (
"Critical",
"Error",
"Warning",
"Info",
"Debug",
"Trace",
"All", # "Not-Set",
]
)

def __init__(self, *args) -> None: # noqa: ANN
def __init__(self, *args) -> None: # noqa: ANN101
logging.Logger.__init__(self, *args)
self._verbosity = 3
self._timeEnable = False
Expand Down Expand Up @@ -251,8 +251,8 @@ def emit(self, record: logging.LogRecord) -> None:

###
if fp is None:
print(f"fp=None, levelname={record.levelname}")
print(msg)
print(f"fp=None, levelname={record.levelname}") # noqa: T201
print(msg) # noqa: T201
return
fp.write(msg + "\n")
fp.flush()
Expand Down Expand Up @@ -334,7 +334,7 @@ def getDataDir() -> str:


def isDebug() -> bool:
return log.getVerbosity() >= 4
return log.getVerbosity() >= 4 # noqa: PLR2004


if os.sep == "\\":
Expand Down
12 changes: 6 additions & 6 deletions pyglossary/ebook_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ class EbookWriter:
</body>
</html>"""
INDEX_XHTML_LINK_TEMPLATE = (
" <span class=\"indexGroup\">"
"<a href=\"{ref}\">{label}</a></span>"
' <span class="indexGroup">'
'<a href="{ref}">{label}</a></span>'
)

INDEX_XHTML_LINK_JOINER = " &#8226;\n"

OPF_MANIFEST_ITEM_TEMPLATE = (
" <item href=\"{ref}\" id=\"{id}\""
" media-type=\"{mediaType}\" />"
' <item href="{ref}" id="{id}"'
' media-type="{mediaType}" />'
)

OPF_SPINE_ITEMREF_TEMPLATE = " <itemref idref=\"{id}\" />"
OPF_SPINE_ITEMREF_TEMPLATE = ' <itemref idref="{id}" />'

OPF_TEMPLATE = ""

Expand Down Expand Up @@ -504,7 +504,7 @@ def write(self) -> "Generator[None, EntryType, None]":

if os.sep == "\\":
shutil.copytree(self._tmpDir, filename)
self._glos._cleanupPathList.add(self._tmpDir) # type: ignore
self._glos._cleanupPathList.add(self._tmpDir) # noqa: SLF001, type: ignore
return

shutil.move(self._tmpDir, filename)
10 changes: 5 additions & 5 deletions pyglossary/entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@
from .glossary_types import RawEntryType


__all__ = ["Entry", "DataEntry"]
__all__ = ["DataEntry", "Entry"]

log = logging.getLogger("pyglossary")


# aka Resource
class DataEntry(BaseEntry):
__slots__ = [
"_fname",
"_byteProgress",
"_data",
"_fname",
"_tmpPath",
"_byteProgress",
]

def isData(self) -> bool:
Expand Down Expand Up @@ -179,10 +179,10 @@ class Entry(BaseEntry):
)

__slots__ = [
"_word",
"_byteProgress",
"_defi",
"_defiFormat",
"_byteProgress",
"_word",
]

def isData(self) -> bool:
Expand Down
8 changes: 4 additions & 4 deletions pyglossary/entry_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@


__all__ = [
"ShowProgressBar",
"EntryFilterType",
"StripFullHtml",
"PreventDuplicateWords",
"entryFiltersRules",
"RemoveHtmlTagsAll",
"ShowMaxMemoryUsage",
"ShowProgressBar",
"StripFullHtml",
"entryFiltersRules",
]


Expand Down Expand Up @@ -423,7 +423,7 @@ def run(self, entry: "EntryType") -> "EntryType | None":
hw_t = hw_t.replace("\u0622", "\u0627").replace("\u0623", "\u0627")
if hw_t == hw or not hw_t:
return entry
entry._word = [hw_t] + words # type: ignore
entry._word = [hw_t, *words] # type: ignore
return entry


Expand Down
9 changes: 5 additions & 4 deletions pyglossary/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@
from typing import TypeAlias

__all__ = [
"YesNoAlwaysNever",
"ALWAYS",
"DEFAULT_NO",
"flagsByName",
"StrWithDesc",
"DEFAULT_YES",
"NEVER",
"ALWAYS",
"StrWithDesc",
"YesNoAlwaysNever",
"flagsByName",
]

flagsByName = {}


class StrWithDesc(str):
desc: str
__slots__ = ["desc"]

def __new__(cls: "type", name: str, desc: str) -> "StrWithDesc":
s: StrWithDesc = str.__new__(cls, name)
Expand Down
8 changes: 4 additions & 4 deletions pyglossary/glossary_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
from .sort_keys import NamedSortKey

__all__ = [
"Callable",
"EntryListType",
"EntryType",
"GlossaryExtendedType",
"GlossaryType",
"RawEntryType",
"GlossaryExtendedType",
"EntryType",
"EntryListType",
"Callable",
]

MultiStr: "TypeAlias" = "str | list[str]"
Expand Down
2 changes: 1 addition & 1 deletion pyglossary/glossary_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def splitFilenameExt(
if not ext:
return filename, filename, "", ""

if ext[1:] in stdCompressions + ("zip", "dz"):
if ext[1:] in (*stdCompressions, "zip", "dz"):
compression = ext[1:]
filename = filenameNoExt
filenameNoExt, ext = splitext(filename)
Expand Down
4 changes: 2 additions & 2 deletions pyglossary/glossary_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def _closeReaders(self) -> None:
for reader in self._readers:
try:
reader.close()
except Exception:
except Exception: # noqa: PERF203
log.exception("")

def clear(self) -> None:
Expand All @@ -149,7 +149,7 @@ def clear(self) -> None:
for reader in readers:
try:
reader.close()
except Exception:
except Exception: # noqa: PERF203
log.exception("")
self._readers: "list[Any]" = []
self._defiHasWordTitle = False
Expand Down
2 changes: 1 addition & 1 deletion pyglossary/html_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ def build_name2codepoint_dict() -> None:
value = name2str[key]
if len(value) > 1:
raise ValueError(f"{value = }")
print(f'\t"{key}": 0x{ord(value):0>4x}, # {value}')
print(f'\t"{key}": 0x{ord(value):0>4x}, # {value}') # noqa: T201


def _sub_unescape_unicode(m: "re.Match") -> str:
Expand Down
2 changes: 1 addition & 1 deletion pyglossary/icu_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from collections.abc import Callable
from typing import AnyStr

__all__ = ["T_Locale", "T_Collator"]
__all__ = ["T_Collator", "T_Locale"]


class T_Locale(typing.Protocol):
Expand Down
12 changes: 6 additions & 6 deletions pyglossary/info.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
__all__ = [
"c_publisher",
"c_author",
"c_targetLang",
"c_sourceLang",
"c_name",
"infoKeysAliasDict",
"c_author",
"c_name",
"c_publisher",
"c_sourceLang",
"c_targetLang",
"infoKeysAliasDict",
]

c_name = "name"
Expand Down
31 changes: 9 additions & 22 deletions pyglossary/langs/writing_system.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import unicodedata
from collections import namedtuple
from typing import Literal, NamedTuple

__all__ = [
"WritingSystem",
Expand All @@ -12,27 +12,14 @@
"writingSystemList",
]

WritingSystem = namedtuple(
"WritingSystem",
[
"name",
"iso", # list[tuple[int, str]]
"unicode",
"titleTag",
"direction", # ltr | rtl | ttb
"comma",
"pop", # population in millions
],
defaults=(
None, # name
[], # iso
[], # unicode
"b", # titleTag
"ltr", # direction
", ", # comma
0, # pop
),
)
class WritingSystem(NamedTuple):
name: str | None = None
iso: list[tuple[int, str]] = []
unicode: list = []
titleTag: str = "b"
direction: Literal["ltr", "rtl", "ttb"] = "ltr"
comma: str = ", "
pop: int = 0 # population in millions

# digits and FULLWIDTH DIGITs are considered neutral/ignored, not Latin

Expand Down
16 changes: 8 additions & 8 deletions pyglossary/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@
from typing import Any

__all__ = [
"Option",
"optionFromDict",
"StrOption",
"FloatOption",
"BoolOption",
"IntOption",
"NewlineOption",
"FileSizeOption",
"DictOption",
"ListOption",
"EncodingOption",
"FileSizeOption",
"FloatOption",
"HtmlColorOption",
"IntOption",
"ListOption",
"NewlineOption",
"Option",
"StrOption",
"optionFromDict",
]

log = logging.getLogger("pyglossary")
Expand Down
13 changes: 5 additions & 8 deletions pyglossary/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@
import os
import shutil
import sys
import types
from collections.abc import Callable
from pathlib import Path
from typing import TYPE_CHECKING

from pyglossary import core

if TYPE_CHECKING:
import types

__all__ = ["showMemoryUsage", "rmtree", "indir", "runDictzip"]
__all__ = ["indir", "rmtree", "runDictzip", "showMemoryUsage"]

log = logging.getLogger("pyglossary")

Expand Down Expand Up @@ -52,9 +49,9 @@ def __enter__(self) -> None:

def __exit__(
self,
exc_type: "type",
exc_val: "Exception",
exc_tb: "types.TracebackType",
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: types.TracebackType | None,
) -> None:
if self.old_pwd:
os.chdir(self.old_pwd)
Expand Down
2 changes: 1 addition & 1 deletion pyglossary/plugin_lib/dictdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,4 +399,4 @@ def getDef(self, word: str) -> "list[bytes]":
# print("------------------------ ", __name__)
if __name__ == "__main__":
db = DictDB("test")
print(db)
print(db) # noqa: T201
2 changes: 1 addition & 1 deletion pyglossary/plugin_lib/readmdict.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
except ImportError:
xxhash = None

__all__ = ["MDX", "MDD"]
__all__ = ["MDD", "MDX"]

log = logging.getLogger(__name__)

Expand Down
Loading

0 comments on commit 4fb9f78

Please sign in to comment.