From 63c0ed3951b3a145d9948dcf2b16f6c413e633c4 Mon Sep 17 00:00:00 2001 From: Jan Lindemann Date: Fri, 11 Sep 2026 14:59:28 +0200 Subject: [PATCH] jwutils.Cmd.add_subcommands(): Collect only Cmd This commit fixes tightening type check fallout. add_subcommands() with a string pattern collects every class of the calling module whose name matches the pattern. inspect.getmembers() yields plain objects, so the unannotated collection list is inferred as list[object], which is not compatible with the declared list[type[Cmd]] parameter type, and make check fails on it. Annotate the collection list as list[type[Cmd]] and narrow it to subclasses of Cmd via issubclass(). This makes the implementation match the declared signature and stops classes lacking the Cmd interface from being registered as subcommands, where they would break later when instantiated and treated as Cmd in __add_cmd_to_parser(). Signed-off-by: Jan Lindemann Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.85.1 --- src/python/jwutils/Cmd.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/python/jwutils/Cmd.py b/src/python/jwutils/Cmd.py index c360c09..74907f1 100644 --- a/src/python/jwutils/Cmd.py +++ b/src/python/jwutils/Cmd.py @@ -45,9 +45,9 @@ class Cmd(abc.ABC): # export def add_subcommands(self, cmd: str | type[Cmd] | list[type[Cmd]]) -> None: if isinstance(cmd, str): - sc = [] + sc: list[type[Cmd]] = [] for name, obj in inspect.getmembers(sys.modules[self.__class__.__module__]): - if inspect.isclass(obj): + if inspect.isclass(obj) and issubclass(obj, Cmd): if re.search(cmd, str(obj)): sc.append(obj) log.slog(log.DEBUG, f"Found subcommand {obj}")