Skip to content

Commit 0d24308

Browse files
committed
Simplified function.
1 parent 6344e23 commit 0d24308

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

cmd2/cmd2.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,18 +1025,22 @@ def unregister_command_set(self, cmdset: CommandSet) -> None:
10251025
self._installed_command_sets.remove(cmdset)
10261026

10271027
def _check_uninstallable(self, cmdset: CommandSet) -> None:
1028+
cmdset_id = id(cmdset)
1029+
10281030
def check_parser_uninstallable(parser: Cmd2ArgumentParser) -> None:
1029-
cmdset_id = id(cmdset)
10301031
try:
10311032
subparsers_action = parser._get_subparsers_action()
1032-
for subparser in subparsers_action.choices.values():
1033-
attached_cmdset_id = getattr(subparser, constants.PARSER_ATTR_COMMANDSET_ID, None)
1034-
if attached_cmdset_id is not None and attached_cmdset_id != cmdset_id:
1035-
raise CommandSetRegistrationError('Cannot uninstall CommandSet when another CommandSet depends on it')
1036-
check_parser_uninstallable(cast(Cmd2ArgumentParser, subparser))
10371033
except ValueError:
10381034
# No subcommands to check
1039-
pass
1035+
return
1036+
1037+
for subparser in subparsers_action.choices.values():
1038+
attached_cmdset_id = getattr(subparser, constants.PARSER_ATTR_COMMANDSET_ID, None)
1039+
if attached_cmdset_id is not None and attached_cmdset_id != cmdset_id:
1040+
raise CommandSetRegistrationError(
1041+
f"Cannot uninstall CommandSet: '{subparser.prog}' is required by another CommandSet"
1042+
)
1043+
check_parser_uninstallable(cast(Cmd2ArgumentParser, subparser))
10401044

10411045
methods: list[tuple[str, Callable[..., Any]]] = inspect.getmembers(
10421046
cmdset,

0 commit comments

Comments
 (0)