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:
Jan Lindemann 2026-07-22 23:03:53 +02:00
commit 1e613a39c6
40 changed files with 228 additions and 179 deletions

View file

@ -4,7 +4,7 @@ import abc
from enum import Enum, auto
from functools import cached_property
from typing import override, TYPE_CHECKING
from typing import Any, override, TYPE_CHECKING
from .log import DEBUG, ERR, log
from .Uri import Uri
@ -24,7 +24,7 @@ class FileContext(abc.ABC):
self,
uri: str | Uri,
interactive: bool | None = None,
verbose_default = False,
verbose_default: bool = False,
chroot: bool = False,
in_pipe: ProcPipeline | None = None,
out_pipe: ProcPipeline | None = None,
@ -43,18 +43,18 @@ class FileContext(abc.ABC):
f'= "{verbose_default}"'
)
async def __aenter__(self):
async def __aenter__(self) -> 'FileContext':
await self.open()
return self
async def __aexit__(self, exc_type, exc, tb):
async def __aexit__(self, exc_type: Any, exc: Any, tb: Any) -> None:
await self.close()
@override
def __repr__(self) -> str:
return self.__uri.id
def __pipe(self, d: Direction):
def __pipe(self, d: Direction) -> 'ProcPipeline':
match d:
case self.Direction.In:
if not self.__in_pipe:
@ -76,7 +76,7 @@ class FileContext(abc.ABC):
return self.root + path
return self.root + '/' + path
def add_proc_filter(self, d: Direction, proc_filter: ProcFilter):
def add_proc_filter(self, d: Direction, proc_filter: ProcFilter) -> None:
self.__pipe(d).append(proc_filter)
async def _open(self) -> None:
@ -298,11 +298,11 @@ class FileContext(abc.ABC):
log(ERR, f'{self.log_name}: Failed to stat({path}) ({str(e)})')
raise
async def is_dir(self, path: str, follow_symlinks = True) -> bool:
async def is_dir(self, path: str, follow_symlinks: bool = True) -> bool:
return await self._is_dir(self._chroot(path), follow_symlinks = follow_symlinks)
@classmethod
def create(cls, uri: str | Uri, *args, **kwargs) -> FileContext:
def create(cls, uri: str | Uri, *args: Any, **kwargs: Any) -> 'FileContext':
uri = Uri.pimp(uri)
match uri.protocol:
case 'local' | 'file':