diff --git a/comicapi/filenamelexer.py b/comicapi/filenamelexer.py index c35d83f..7b86449 100644 --- a/comicapi/filenamelexer.py +++ b/comicapi/filenamelexer.py @@ -90,7 +90,8 @@ class Item: class Lexer: def __init__(self, string: str) -> None: self.input: str = string # The string being scanned - self.state: Callable[[Lexer], Callable | None] | None = None # The next lexing function to enter + # The next lexing function to enter + self.state: Callable[[Lexer], Callable | None] | None = None # type: ignore[type-arg] self.pos: int = -1 # Current position in the input self.start: int = 0 # Start position of this item self.lastPos: int = 0 # Position of most recent item returned by nextItem @@ -172,13 +173,13 @@ class Lexer: # Errorf returns an error token and terminates the scan by passing # Back a nil pointer that will be the next state, terminating self.nextItem. -def errorf(lex: Lexer, message: str) -> Callable[[Lexer], Callable | None] | None: +def errorf(lex: Lexer, message: str) -> Callable[[Lexer], Callable | None] | None: # type: ignore[type-arg] lex.items.append(Item(ItemType.Error, lex.start, message)) return None # Scans the elements inside action delimiters. -def lex_filename(lex: Lexer) -> Callable[[Lexer], Callable | None] | None: +def lex_filename(lex: Lexer) -> Callable[[Lexer], Callable | None] | None: # type: ignore[type-arg] r = lex.get() if r == eof: if lex.paren_depth != 0: @@ -257,7 +258,7 @@ def lex_filename(lex: Lexer) -> Callable[[Lexer], Callable | None] | None: return lex_filename -def lex_operator(lex: Lexer) -> Callable: +def lex_operator(lex: Lexer) -> Callable: # type: ignore[type-arg] lex.accept_run("-|:;") lex.emit(ItemType.Operator) return lex_filename @@ -265,7 +266,7 @@ def lex_operator(lex: Lexer) -> Callable: # LexSpace scans a run of space characters. # One space has already been seen. -def lex_space(lex: Lexer) -> Callable: +def lex_space(lex: Lexer) -> Callable: # type: ignore[type-arg] while is_space(lex.peek()): lex.get() @@ -274,7 +275,7 @@ def lex_space(lex: Lexer) -> Callable: # Lex_text scans an alphanumeric. -def lex_text(lex: Lexer) -> Callable: +def lex_text(lex: Lexer) -> Callable: # type: ignore[type-arg] while True: r = lex.get() if is_alpha_numeric(r): @@ -313,7 +314,7 @@ def cal(value: str) -> set[Any]: return set(month_abbr + month_name + day_abbr + day_name) -def lex_number(lex: Lexer) -> Callable[[Lexer], Callable | None] | None: +def lex_number(lex: Lexer) -> Callable[[Lexer], Callable | None] | None: # type: ignore[type-arg] if not lex.scan_number(): return errorf(lex, "bad number syntax: " + lex.input[lex.start : lex.pos]) # Complex number logic removed. Messes with math operations without space diff --git a/comicapi/filenameparser.py b/comicapi/filenameparser.py index c19c522..14cc060 100644 --- a/comicapi/filenameparser.py +++ b/comicapi/filenameparser.py @@ -343,7 +343,7 @@ class Parser: remove_fcbd: bool = False, remove_publisher: bool = False, ) -> None: - self.state: Callable[[Parser], Callable | None] | None = None + self.state: Callable[[Parser], Callable | None] | None = None # type: ignore[type-arg] self.pos = -1 self.firstItem = True @@ -412,7 +412,7 @@ class Parser: self.state = self.state(self) -def parse(p: Parser) -> Callable[[Parser], Callable | None] | None: +def parse(p: Parser) -> Callable[[Parser], Callable | None] | None: # type: ignore[type-arg] item: filenamelexer.Item = p.get() # We're done, time to do final processing @@ -670,7 +670,7 @@ def parse(p: Parser) -> Callable[[Parser], Callable | None] | None: # TODO: What about more esoteric numbers??? -def parse_issue_number(p: Parser) -> Callable[[Parser], Callable | None] | None: +def parse_issue_number(p: Parser) -> Callable[[Parser], Callable | None] | None: # type: ignore[type-arg] item = p.input[p.pos] if "issue" in p.filename_info: @@ -702,7 +702,7 @@ def parse_issue_number(p: Parser) -> Callable[[Parser], Callable | None] | None: return parse -def parse_series(p: Parser) -> Callable[[Parser], Callable | None] | None: +def parse_series(p: Parser) -> Callable[[Parser], Callable | None] | None: # type: ignore[type-arg] item = p.input[p.pos] series: list[list[filenamelexer.Item]] = [[]] @@ -908,7 +908,7 @@ def resolve_issue(p: Parser) -> None: p.filename_info["issue"] = p.filename_info["volume"] -def parse_finish(p: Parser) -> Callable[[Parser], Callable | None] | None: +def parse_finish(p: Parser) -> Callable[[Parser], Callable | None] | None: # type: ignore[type-arg] resolve_year(p) resolve_issue(p) @@ -1014,7 +1014,7 @@ def get_remainder(p: Parser) -> str: return remainder.strip() -def parse_info_specifier(p: Parser) -> Callable[[Parser], Callable | None] | None: +def parse_info_specifier(p: Parser) -> Callable[[Parser], Callable | None] | None: # type: ignore[type-arg] item = p.input[p.pos] index = p.pos diff --git a/comicapi/genericmetadata.py b/comicapi/genericmetadata.py index 4b7e4da..216c099 100644 --- a/comicapi/genericmetadata.py +++ b/comicapi/genericmetadata.py @@ -129,7 +129,7 @@ class GenericMetadata: last_mark: str | None = None cover_image: str | None = None - def __post_init__(self): + def __post_init__(self) -> None: for key, value in self.__dict__.items(): if value and key != "is_empty": self.is_empty = False diff --git a/comictaggerlib/filerenamer.py b/comictaggerlib/filerenamer.py index 8fc59af..e420d31 100644 --- a/comictaggerlib/filerenamer.py +++ b/comictaggerlib/filerenamer.py @@ -71,7 +71,7 @@ class MetadataFormatter(string.Formatter): ) -> None: super().__init__() self.smart_cleanup = smart_cleanup - self.platform = normalize_platform(platform) + self.platform = str(normalize_platform(platform)) self.replacements = replacements def format_field(self, value: Any, format_spec: str) -> str: @@ -221,7 +221,7 @@ class FileRenamer: self.template = template def determine_name(self, ext: str) -> str: - class Default(dict): + class Default(dict[str, Any]): def __missing__(self, key: str) -> str: return "{" + key + "}" diff --git a/comictaggerlib/main.py b/comictaggerlib/main.py index 79bde77..47e13a2 100755 --- a/comictaggerlib/main.py +++ b/comictaggerlib/main.py @@ -94,7 +94,7 @@ try: class Application(QtWidgets.QApplication): openFileRequest = QtCore.pyqtSignal(QtCore.QUrl, name="openfileRequest") - def event(self, event): + def event(self, event: QtCore.QEvent) -> bool: if event.type() == QtCore.QEvent.FileOpen: logger.info(event.url().toLocalFile()) self.openFileRequest.emit(event.url()) diff --git a/comictaggerlib/settings.py b/comictaggerlib/settings.py index 2bb0e36..17b7c5d 100644 --- a/comictaggerlib/settings.py +++ b/comictaggerlib/settings.py @@ -158,9 +158,9 @@ class ComicTaggerSettings: # make sure rar program is now in the path for the rar class utils.add_to_path(os.path.dirname(self.rar_exe_path)) - def reset(self): + def reset(self) -> None: os.unlink(self.settings_file) - self.__init__(ComicTaggerSettings.folder) + self.__init__(ComicTaggerSettings.folder) # type: ignore[misc] def load(self) -> None: def readline_generator(f: TextIO) -> Iterator[str]: diff --git a/localefix.py b/localefix.py index 8e1b355..b7bf897 100644 --- a/localefix.py +++ b/localefix.py @@ -7,7 +7,7 @@ import subprocess import sys -def _lang_code_mac(): +def _lang_code_mac() -> str: """ stolen from https://github.com/mu-editor/mu Returns the user's language preference as defined in the Language & Region @@ -38,13 +38,13 @@ def _lang_code_mac(): return lang_code -def configure_locale(): +def configure_locale() -> None: if sys.platform == "darwin" and "LANG" not in os.environ: code = _lang_code_mac() if code != "": os.environ["LANG"] = f"{code}.utf-8" locale.setlocale(locale.LC_ALL, "") - sys.stdout.reconfigure(encoding=sys.getdefaultencoding()) - sys.stderr.reconfigure(encoding=sys.getdefaultencoding()) - sys.stdin.reconfigure(encoding=sys.getdefaultencoding()) + sys.stdout.reconfigure(encoding=sys.getdefaultencoding()) # type: ignore[attr-defined] + sys.stderr.reconfigure(encoding=sys.getdefaultencoding()) # type: ignore[attr-defined] + sys.stdin.reconfigure(encoding=sys.getdefaultencoding()) # type: ignore[attr-defined]