Skip to content

Commit 0cf8c03

Browse files
committed
Restored PARSER_ATTR_OWNER_ID name.
1 parent 8391979 commit 0cf8c03

2 files changed

Lines changed: 12 additions & 12 deletions

File tree

cmd2/cmd2.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,17 +1068,16 @@ def _check_uninstallable(self, cmdset: CommandSet[Any]) -> None:
10681068
10691069
This method acts as a safety guard before unregistration. It inspects all
10701070
command parsers provided by the CommandSet and recursively checks their
1071-
subcommand hierarchies to ensure no other registrant (another CommandSet
1072-
or the main application) has attached subcommands to them.
1071+
subcommand hierarchies to ensure no other CommandSet or Cmd instance has
1072+
attached subcommands to them.
10731073
10741074
:param cmdset: the CommandSet instance to check for uninstallation safety
1075-
:raises CommandSetRegistrationError: if any parser in the CommandSet is
1076-
required by another registrant
1075+
:raises CommandSetRegistrationError: if it is not safe to uninstall the CommandSet
10771076
"""
1078-
registrant_id = id(cmdset)
1077+
cmdset_id = id(cmdset)
10791078

10801079
def check_parser_uninstallable(parser: Cmd2ArgumentParser) -> None:
1081-
# Recursively verify no subcommands belong to a different registrant
1080+
# Recursively verify no subcommands belong to a different CommandSet or Cmd instance
10821081
try:
10831082
subparsers_action = parser.get_subparsers_action()
10841083
except ValueError:
@@ -1093,10 +1092,11 @@ def check_parser_uninstallable(parser: Cmd2ArgumentParser) -> None:
10931092
continue
10941093
checked_parsers.add(subparser)
10951094

1096-
attached_registrant_id = getattr(subparser, constants.PARSER_ATTR_REGISTRANT_ID, None)
1097-
if attached_registrant_id is not None and attached_registrant_id != registrant_id:
1095+
owner_id = getattr(subparser, constants.PARSER_ATTR_OWNER_ID, None)
1096+
if owner_id is not None and owner_id != cmdset_id:
10981097
raise CommandSetRegistrationError(
1099-
f"Cannot uninstall CommandSet: '{subparser.prog}' is required by another registrant"
1098+
f"Cannot uninstall CommandSet '{type(cmdset).__name__}' because it is still "
1099+
f"required by subcommand '{subparser.prog}'"
11001100
)
11011101
check_parser_uninstallable(subparser)
11021102

@@ -1152,7 +1152,7 @@ def _register_subcommands(self, owner: CmdOrSet) -> None:
11521152
subcmd_parser.set_defaults(**defaults)
11531153

11541154
# Record the ID of the instance that registered this subcommand parser
1155-
setattr(subcmd_parser, constants.PARSER_ATTR_REGISTRANT_ID, id(owner))
1155+
setattr(subcmd_parser, constants.PARSER_ATTR_OWNER_ID, id(owner))
11561156

11571157
# Attach this subcommand
11581158
record = SubcommandRecord(

cmd2/constants.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ def cmd2_public_attr_name(name: str) -> str:
7878
# Attached to a subcommand function; defines its SubcommandSpec instance
7979
SUBCOMMAND_ATTR_SPEC = cmd2_private_attr_name("subcommand_spec")
8080

81-
# Attached to an argparse parser; stores the id() of the Cmd or CommandSet instance that registered it
82-
PARSER_ATTR_REGISTRANT_ID = cmd2_private_attr_name("registrant_id")
81+
# Attached to a subcommand parser; stores the id() of the Cmd or CommandSet instance that registered it
82+
PARSER_ATTR_OWNER_ID = cmd2_private_attr_name("owner_id")
8383

8484

8585
# --- Public Developer Attributes ---

0 commit comments

Comments
 (0)