@@ -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 (
0 commit comments