App, lib: Add type annotations to untyped functions
Add missing type annotations to functions that are called from typed contexts, satisfying the new disallow_untyped_calls mypy rule. Fixes: - Local.py: __log() with typed parameters - lib/App.py: _add_arguments(), add_cmd_to_parser(), add_cmds_to_parser() - pm/rpm.py, dpkg.py: meta_map() return type - Exec.py: __init_askpass() return type - App.py: strip_module_from_spec(), __get_project_refs_cached(), ResultCache.__init__ and run(), _add_arguments() - Added Collection type for truthy-iterable compliance Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL and pi.dev 0.81.1 Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
75c9879f67
commit
410fd7ab5c
6 changed files with 26 additions and 15 deletions
|
|
@ -10,7 +10,7 @@ import sys
|
|||
|
||||
from enum import Enum, auto
|
||||
from functools import cache
|
||||
from typing import override, TYPE_CHECKING
|
||||
from typing import Any, override, TYPE_CHECKING
|
||||
|
||||
from .lib.App import App as Base
|
||||
from .lib.Distro import Distro
|
||||
|
|
@ -19,6 +19,7 @@ from .lib.ProjectConf import ProjectConf
|
|||
|
||||
if TYPE_CHECKING:
|
||||
import argparse
|
||||
from argparse import ArgumentParser
|
||||
|
||||
from typing import TypeAlias
|
||||
|
||||
|
|
@ -36,10 +37,10 @@ if TYPE_CHECKING:
|
|||
|
||||
class ResultCache(object):
|
||||
|
||||
def __init__(self):
|
||||
self.__cache = {}
|
||||
def __init__(self) -> None:
|
||||
self.__cache: dict[str, Any] = {}
|
||||
|
||||
def run(self, func, args):
|
||||
def run(self, func, args: list[Any]) -> object:
|
||||
d = self.__cache
|
||||
depth = 0
|
||||
keys = [func.__name__] + args
|
||||
|
|
@ -200,7 +201,15 @@ class App(Base):
|
|||
return None
|
||||
|
||||
def __get_project_refs_cached(
|
||||
self, buf, visited, spec, section, key, add_self, scope, names_only
|
||||
self,
|
||||
buf: list[str],
|
||||
visited: set[str],
|
||||
spec: str,
|
||||
section: str,
|
||||
key: str,
|
||||
add_self: bool,
|
||||
scope: Scope,
|
||||
names_only: bool,
|
||||
):
|
||||
return self.__res_cache.run(
|
||||
self.__get_project_refs,
|
||||
|
|
@ -381,7 +390,7 @@ class App(Base):
|
|||
self.__exec_context = None
|
||||
|
||||
@override
|
||||
def _add_arguments(self, parser) -> None:
|
||||
def _add_arguments(self, parser: ArgumentParser) -> None:
|
||||
super()._add_arguments(parser)
|
||||
parser.add_argument('-t', '--topdir', default = None, help = 'Project Path')
|
||||
parser.add_argument(
|
||||
|
|
@ -537,7 +546,7 @@ class App(Base):
|
|||
def tmpl_dir(self, name: str) -> str | None:
|
||||
return self.find_dir(name, ['/tmpl'], ['/opt/' + name + '/share/tmpl'])
|
||||
|
||||
def strip_module_from_spec(self, mod):
|
||||
def strip_module_from_spec(self, mod: str) -> str:
|
||||
return re.sub(r'-dev$|-devel$|-run$', '', re.split('([=><]+)', mod)[0].strip())
|
||||
|
||||
@cache
|
||||
|
|
|
|||
Loading…
Reference in a new issue