lib.App: Use args parameter in _run()

_run() receives the parsed arguments as its args parameter, but then
checks the private __args attribute for the func attribute and resolves
the command function through the args property. Both refer to the same
object today, so the mixing is harmless, but it obscures the data flow
and would silently diverge if a caller ever passed a namespace other
than the stored one.

Use the args parameter consistently in _run().

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-08-14 23:55:05 +02:00
commit f706477f18
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -318,11 +318,11 @@ class App: # export
# want to do something else, for instance if you don't have sub-commands,
# or if want to do anything before and / or after the subcommands.
async def _run(self, args: Namespace) -> None | int:
if not hasattr(self.__args, 'func'):
if not hasattr(args, 'func'):
self.__parser.print_help()
return None
# Run sub-command. Overwrite if you want to do anything before or after
return cast('None | int', await self.args.func(args))
return cast('None | int', await args.func(args))
def call_async(self, awaitable: Awaitable[T], timeout: float | None = None) -> T:
return self.async_runner.call(awaitable, timeout)