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
|
|
@ -5,7 +5,7 @@ import os
|
|||
import sys
|
||||
|
||||
from enum import Enum, auto
|
||||
from typing import TYPE_CHECKING, Iterable, TypeVar
|
||||
from typing import TYPE_CHECKING, Any, Iterable, TypeVar, cast
|
||||
|
||||
from .base import Input, InputMode, Result
|
||||
from .log import DEBUG, ERR, log
|
||||
|
|
@ -23,7 +23,7 @@ class AskpassKey(Enum):
|
|||
Username = auto()
|
||||
Password = auto()
|
||||
|
||||
def pretty_cmd(cmd: list[str] | None = None, wd = None):
|
||||
def pretty_cmd(cmd: list[str] | None = None, wd: str | None = None) -> str:
|
||||
if cmd is None:
|
||||
cmd = sys.argv
|
||||
tokens = [cmd[0]]
|
||||
|
|
@ -38,11 +38,11 @@ def pretty_cmd(cmd: list[str] | None = None, wd = None):
|
|||
|
||||
# See ExecContext.run() for what this function does
|
||||
async def run_cmd(
|
||||
*args,
|
||||
*args: Any,
|
||||
ec: ExecContext | None = None,
|
||||
verbose: bool | None = None,
|
||||
cmd_input: Input = InputMode.NonInteractive,
|
||||
**kwargs,
|
||||
**kwargs: Any,
|
||||
) -> Result:
|
||||
if verbose is None:
|
||||
verbose = False if ec is None else ec.verbose_default
|
||||
|
|
@ -56,12 +56,12 @@ async def run_cmd(
|
|||
|
||||
async def run_curl(
|
||||
args: list[str],
|
||||
wd = None,
|
||||
throw = None,
|
||||
verbose = None,
|
||||
cmd_input = InputMode.NonInteractive,
|
||||
wd: str | None = None,
|
||||
throw: bool | None = None,
|
||||
verbose: bool | None = None,
|
||||
cmd_input: Input = InputMode.NonInteractive,
|
||||
ec: ExecContext | None = None,
|
||||
decode = False,
|
||||
decode: bool = False,
|
||||
) -> Result:
|
||||
if verbose is None:
|
||||
verbose = False if ec is None else ec.verbose_default
|
||||
|
|
@ -76,7 +76,7 @@ async def run_curl(
|
|||
async def run_curl_into(
|
||||
expected_type: type[T],
|
||||
args: list[str],
|
||||
**kwargs,
|
||||
**kwargs: Any,
|
||||
) -> T:
|
||||
result = await run_curl(args, **kwargs)
|
||||
stdout = result.stdout_str
|
||||
|
|
@ -139,11 +139,11 @@ async def run_askpass(
|
|||
|
||||
async def run_sudo(
|
||||
cmd: list[str],
|
||||
*args,
|
||||
*args: Any,
|
||||
interactive: bool = True,
|
||||
ec: ExecContext | None = None,
|
||||
**kwargs,
|
||||
):
|
||||
**kwargs: Any,
|
||||
) -> Result:
|
||||
if ec is None:
|
||||
from .ec.Local import Local
|
||||
|
||||
|
|
@ -152,10 +152,10 @@ async def run_sudo(
|
|||
|
||||
async def get(
|
||||
uri: str | Uri,
|
||||
*args,
|
||||
*args: Any,
|
||||
ctx: FileContext | None = None,
|
||||
content_filter: ProcFilter | list[ProcFilter] | ProcPipeline | None = None,
|
||||
**kwargs,
|
||||
**kwargs: Any,
|
||||
) -> Result:
|
||||
uri = Uri.pimp(uri)
|
||||
if ctx is None or uri.id != ctx.uri.id:
|
||||
|
|
@ -172,7 +172,7 @@ async def copy(
|
|||
owner: str | None = None,
|
||||
group: str | None = None,
|
||||
mode: int | None = None,
|
||||
throw = True,
|
||||
throw: bool = True,
|
||||
) -> Exception | str | list[str]:
|
||||
if not isinstance(src_uri, str):
|
||||
ret: list[str] = []
|
||||
|
|
@ -225,7 +225,7 @@ async def get_username( # export
|
|||
f'Username mismatch: called with --username="{args.username}", '
|
||||
f'URL has user name "{url_user}"'
|
||||
)
|
||||
return args.username
|
||||
return str(args.username)
|
||||
if url_user is not None:
|
||||
return url_user
|
||||
return await run_askpass(askpass_env, AskpassKey.Username, ec = ec)
|
||||
|
|
@ -244,7 +244,7 @@ async def get_password( # export
|
|||
if args is not None and hasattr(args, 'password'):
|
||||
# use getattr(), because we don't necessarily want to have insecure
|
||||
# --password among options
|
||||
ret = getattr(args, 'password')
|
||||
ret = cast('str | None', getattr(args, 'password'))
|
||||
if ret is not None:
|
||||
return ret
|
||||
if url is not None:
|
||||
|
|
|
|||
Loading…
Reference in a new issue