From 04517637ddea5a41dc9445092cf4d48f57b6aff2 Mon Sep 17 00:00:00 2001 From: dskrypa Date: Sat, 20 Dec 2025 08:38:06 -0500 Subject: [PATCH] removed unnecessary command_parent attribute from CommandParameters --- lib/cli_command_parser/command_parameters.py | 12 ++---------- lib/cli_command_parser/core.py | 2 +- tests/test_commands/test_command_meta.py | 4 ++-- 3 files changed, 5 insertions(+), 13 deletions(-) diff --git a/lib/cli_command_parser/command_parameters.py b/lib/cli_command_parser/command_parameters.py index 55d1108e..fa2ec8ff 100644 --- a/lib/cli_command_parser/command_parameters.py +++ b/lib/cli_command_parser/command_parameters.py @@ -34,7 +34,6 @@ class CommandParameters: # fmt: off command: CommandCls #: The Command associated with this CommandParameters object formatter: CommandHelpFormatter #: The formatter used for this Command's help text - command_parent: CommandCls | None #: The parent Command, if any parent: CommandParameters | None #: The parent Command's CommandParameters action: Action | None = None #: An Action Parameter, if specified _pass_thru: PassThru | None = None #: A PassThru Parameter, if specified @@ -49,15 +48,8 @@ class CommandParameters: option_map: OptionMap #: Mapping of {--opt / -opt: Parameter} # fmt: on - def __init__( - self, - command: CommandCls, - command_parent: CommandCls | None, - parent_params: CommandParameters | None, - config: CommandConfig, - ): + def __init__(self, command: CommandCls, parent_params: CommandParameters | None, config: CommandConfig): self.command = command - self.command_parent = command_parent self.parent = parent_params self.config = config self._process_parameters() @@ -167,7 +159,7 @@ def _process_parameters(self): while param_group := param_group.group: groups.add(param_group) - if self.config.add_help and self.command_parent is not None and (not self.parent or not self.parent._has_help): + if self.config.add_help and self.parent is not None and not self.parent._has_help: options.append(help_action) self._process_positionals(positionals) diff --git a/lib/cli_command_parser/core.py b/lib/cli_command_parser/core.py index 5d5f030e..35726f01 100644 --- a/lib/cli_command_parser/core.py +++ b/lib/cli_command_parser/core.py @@ -211,7 +211,7 @@ def params(mcs, cls: CommandAny) -> CommandParameters: cls = cls.__class__ parent = mcs.parent(cls, True) parent_params = mcs.params(parent) if parent is not None else None - cls.__params = params = CommandParameters(cls, parent, parent_params, mcs.config(cls, DEFAULT_CONFIG)) + cls.__params = params = CommandParameters(cls, parent_params, mcs.config(cls, DEFAULT_CONFIG)) return params @classmethod diff --git a/tests/test_commands/test_command_meta.py b/tests/test_commands/test_command_meta.py index 9875f971..633dfead 100755 --- a/tests/test_commands/test_command_meta.py +++ b/tests/test_commands/test_command_meta.py @@ -4,7 +4,7 @@ from unittest import TestCase, main from cli_command_parser import Command, CommandConfig -from cli_command_parser.core import CommandMeta, _choice_items, get_config, get_params, get_parent +from cli_command_parser.core import CommandMeta, _choice_items, get_config, get_parent from cli_command_parser.exceptions import CommandDefinitionError _get_config = CommandMeta.config @@ -49,7 +49,7 @@ class Foo(Command): class Bar(Foo): pass - self.assertEqual(get_params(Bar).command_parent, Foo) + self.assertEqual(get_parent(Bar), Foo) def test_choice_items_results(self): cases = [