App, cmds, lib: Fix Any returns from typed functions
Add type annotations and casts to functions that were returning Any where a specific type was declared, satisfying the new warn_return_any mypy rule. Fixes: - log.py: get_caller_pos return type via cast - AsyncRunner.py: cast T for fut.result() - util.py: cast for getattr result, str() for args.username - FileContext.py: verbose_default bool annotation - SSHClient.py: cast SSHClient for dynamic import - lib/App.py: cast ArgumentParser, add return types to inner funcs - pm/rpm.py, dpkg.py: cast Iterable[Package] - App.py: cast for self.args.func(), add return types to inner funcs - BaseCmdPkgRelations.py: cast str for args.delimiter 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
b3fee32ee1
commit
1e613a39c6
40 changed files with 228 additions and 179 deletions
|
|
@ -6,6 +6,7 @@ from ..App import App as Parent
|
|||
from ..CmdBase import CmdBase as Base
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import Namespace
|
||||
from typing import Iterable
|
||||
from ..lib.Distro import Distro
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ class Cmd(Base): # export
|
|||
super().__init__(parent, name, help, aliases = aliases)
|
||||
|
||||
@override
|
||||
async def _run(self, args):
|
||||
async def _run(self, args: 'Namespace') -> None:
|
||||
# Missing subcommand
|
||||
self.print_help(1)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, override
|
|||
from .Cmd import Cmd, Parent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
class CmdPkg(Cmd): # export
|
||||
|
||||
|
|
@ -19,7 +19,7 @@ class CmdPkg(Cmd): # export
|
|||
self.load_subcommands()
|
||||
|
||||
@override
|
||||
async def _run(self, args):
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
import sys
|
||||
|
||||
# Missing subcommand
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, override
|
|||
from .Cmd import Cmd, Parent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
class CmdPlatform(Cmd): # export
|
||||
|
||||
|
|
@ -16,7 +16,7 @@ class CmdPlatform(Cmd): # export
|
|||
self.load_subcommands()
|
||||
|
||||
@override
|
||||
async def _run(self, args):
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
import sys
|
||||
|
||||
# Missing subcommand
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, override
|
|||
from .Cmd import Cmd, Parent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
class CmdPosix(Cmd): # export
|
||||
|
||||
|
|
@ -21,7 +21,7 @@ class CmdPosix(Cmd): # export
|
|||
self.load_subcommands()
|
||||
|
||||
@override
|
||||
async def _run(self, args):
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
import sys
|
||||
|
||||
# Missing subcommand
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, override
|
|||
from .Cmd import Cmd, Parent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
class CmdProjects(Cmd): # export
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ class CmdProjects(Cmd): # export
|
|||
self.load_subcommands()
|
||||
|
||||
@override
|
||||
async def _run(self, args):
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
import sys
|
||||
|
||||
# Missing subcommand
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, override
|
|||
from .Cmd import Cmd, Parent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
class CmdSecrets(Cmd): # export
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ class CmdSecrets(Cmd): # export
|
|||
self.load_subcommands()
|
||||
|
||||
@override
|
||||
async def _run(self, args):
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
import sys
|
||||
|
||||
# Missing subcommand
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, override
|
|||
from .Cmd import Cmd, Parent
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
class CmdTar(Cmd): # export
|
||||
|
||||
|
|
@ -14,7 +14,7 @@ class CmdTar(Cmd): # export
|
|||
self.load_subcommands()
|
||||
|
||||
@override
|
||||
async def _run(self, args):
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
import sys
|
||||
|
||||
# Missing subcommand
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from contextlib import asynccontextmanager
|
||||
from typing import override, TYPE_CHECKING
|
||||
from typing import Any, override, TYPE_CHECKING
|
||||
|
||||
from ....CmdBase import CmdBase as Base
|
||||
from ....lib.FileContext import FileContext
|
||||
|
|
@ -20,7 +20,7 @@ class Cmd(Base): # export
|
|||
self.__tar_io: None = None
|
||||
|
||||
@asynccontextmanager
|
||||
async def ctx(self, **kwargs) -> AsyncIterator[TarIo]:
|
||||
async def ctx(self, **kwargs: Any) -> AsyncIterator[TarIo]:
|
||||
async with TarIo.create(src = self.app.args.archive_path, **kwargs) as ret:
|
||||
ret.src.add_proc_filter(
|
||||
FileContext.Direction.In, ProcFilterGpg(ec = self.app.exec_context)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ from __future__ import annotations
|
|||
|
||||
import re
|
||||
|
||||
from typing import TYPE_CHECKING, override
|
||||
from typing import TYPE_CHECKING, cast, override
|
||||
|
||||
from .Cmd import Cmd, Parent
|
||||
from .lib.pkg_relations import VersionSyntax
|
||||
|
|
@ -17,7 +17,7 @@ class BaseCmdPkgRelations(Cmd):
|
|||
|
||||
def pkg_relations(self, rel_type: str, args: Namespace) -> str:
|
||||
|
||||
return args.delimiter.join(
|
||||
return cast('str', args.delimiter).join(
|
||||
pkg_relations_list(
|
||||
self.app,
|
||||
rel_type = rel_type,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class CmdCanonicalizeRemotes(Cmd): # export
|
|||
@override
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
|
||||
async def git(cmd: list[str], ro = False, throw = True) -> Result:
|
||||
async def git(cmd: list[str], ro: bool = False, throw: bool = True) -> Result:
|
||||
cmd = ['/usr/bin/git', *cmd]
|
||||
log(NOTICE, f'-- {" ".join(cmd)}')
|
||||
if ro or not args.dry_run:
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ from .Cmd import Cmd, Parent
|
|||
from typing import TYPE_CHECKING, override
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from argparse import ArgumentParser
|
||||
from argparse import ArgumentParser, Namespace
|
||||
|
||||
class CmdCheck(Cmd): # export
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ class CmdCheck(Cmd): # export
|
|||
self.load_subcommands()
|
||||
|
||||
@override
|
||||
async def _run(self, args):
|
||||
async def _run(self, args: Namespace) -> None:
|
||||
import sys
|
||||
|
||||
# Missing subcommand
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ from .Cmd import Cmd, Parent
|
|||
from .lib.pkg_relations import VersionSyntax, pkg_relations
|
||||
from .lib.templates import ListDict, RenderValues, tmpl_render
|
||||
|
||||
def key_value(s):
|
||||
def key_value(s: str) -> tuple[str, str]:
|
||||
try:
|
||||
key, value = s.split('=', 1)
|
||||
except ValueError:
|
||||
|
|
@ -51,8 +51,8 @@ class CmdCreateFile(Cmd): # export
|
|||
self,
|
||||
template_name: str,
|
||||
values: list[RenderValues],
|
||||
li_quote = False,
|
||||
li_delimiter = '\n',
|
||||
li_quote: bool = False,
|
||||
li_delimiter: str = '\n',
|
||||
) -> str:
|
||||
return tmpl_render(
|
||||
template_name,
|
||||
|
|
|
|||
|
|
@ -26,8 +26,8 @@ def pkg_relations(
|
|||
ignore: set[str] = set(),
|
||||
quote: bool = False,
|
||||
skip_excluded: bool = False,
|
||||
hide_self = False,
|
||||
hide_jw_pkg = False,
|
||||
hide_self: bool = False,
|
||||
hide_jw_pkg: bool = False,
|
||||
) -> list[str]:
|
||||
|
||||
if subsections is None:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import textwrap
|
||||
from typing import Iterable, TypeAlias, TypeGuard
|
||||
from typing import Any, Iterable, TypeAlias, TypeGuard
|
||||
|
||||
TupleList: TypeAlias = Iterable[tuple[str, str]]
|
||||
ListDict: TypeAlias = dict[str, list[str]]
|
||||
|
|
@ -73,7 +73,7 @@ def format_list_dict(
|
|||
template: str, values: ListDict | dict[str, str], li_quote: bool, li_delimiter: str
|
||||
) -> str:
|
||||
|
||||
def __format_value(val):
|
||||
def __format_value(val: Any) -> str:
|
||||
if not li_quote:
|
||||
return str(val)
|
||||
return f'"{val}"'
|
||||
|
|
@ -144,9 +144,9 @@ _templates = {
|
|||
def tmpl_render(
|
||||
template_name: str,
|
||||
values: list[RenderValues],
|
||||
li_quote = False,
|
||||
li_delimiter = '\n',
|
||||
search_path: list[str] = []
|
||||
li_quote: bool = False,
|
||||
li_delimiter: str = '\n',
|
||||
search_path: list[str] | None = None,
|
||||
) -> str:
|
||||
|
||||
def __format(template: str) -> str:
|
||||
|
|
@ -157,7 +157,7 @@ def tmpl_render(
|
|||
li_delimiter = li_delimiter,
|
||||
)
|
||||
|
||||
for d in search_path:
|
||||
for d in search_path if search_path else []:
|
||||
path = d + '/' + template_name
|
||||
try:
|
||||
with open(path, 'r') as f:
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ class FilesContext:
|
|||
def ctx(self) -> FileContext:
|
||||
return self.__ctx
|
||||
|
||||
async def _read_key_value_file(self, path: str, throw = False) -> dict[str, str]:
|
||||
async def _read_key_value_file(
|
||||
self,
|
||||
path: str,
|
||||
throw: bool = False,
|
||||
) -> dict[str, str]:
|
||||
ret: dict[str, str] = {}
|
||||
try:
|
||||
result = await self.ctx.get(path)
|
||||
|
|
|
|||
Loading…
Reference in a new issue