lib.{App,Cmd}: Pass parent= by name to Cmd* constructors
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 5m40s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m45s
CI / Packaging test (pull_request) Successful in 0s
CI / Packaging - Kali Linux (push) Successful in 5m12s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 4m37s
CI / Packaging test (push) Successful in 0s

The framework instantiates command classes in two places: the top-level
commands in App and the lazily materialized subcommands in
Cmd.add_subcommands(). Both pass the parent parameter positionally.

Change that to passing parent by keyword at both call sites. Every command
class names its first __init__() parameter parent, so the keyword form
binds the same slot for all of them regardless of parameter order, and it
allows a command class to declare parent as keyword-only.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-09-20 06:23:16 +02:00
commit 3602e3ce0d
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61
2 changed files with 2 additions and 2 deletions

View file

@ -220,7 +220,7 @@ class App: # export
type_name_filter = name_filter,
type_filter = [AbstractCmd],
)
self.__cmds = [cmd_class(self) for cmd_class in cmd_classes]
self.__cmds = [cmd_class(parent = self) for cmd_class in cmd_classes]
self._build_parser()
def _build_parser(self, argv: list[str] | None = None) -> None:

View file

@ -126,7 +126,7 @@ class AbstractCmd(abc.ABC):
if cmd_class in self.__child_classes:
continue
self.__child_classes.append(cmd_class)
cmd = cmd_class(self)
cmd = cmd_class(parent = self)
self.__children.append(cmd)
assert len(self.__children) == len(self.__child_classes)
except Exception as e: