Skip to content

Commit 263aa3f

Browse files
committed
Accepted some automated refactorings from the ruff RUF ruleset
1 parent b4f143c commit 263aa3f

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

cmd2/cmd2.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -944,7 +944,7 @@ def _register_subcommands(self, cmdset: Union[CommandSet, 'Cmd']) -> None:
944944

945945
subcommand_valid, errmsg = self.statement_parser.is_valid_command(subcommand_name, is_subcommand=True)
946946
if not subcommand_valid:
947-
raise CommandSetRegistrationError(f'Subcommand {str(subcommand_name)} is not valid: {errmsg}')
947+
raise CommandSetRegistrationError(f'Subcommand {subcommand_name!s} is not valid: {errmsg}')
948948

949949
command_tokens = full_command_name.split()
950950
command_name = command_tokens[0]
@@ -957,13 +957,11 @@ def _register_subcommands(self, cmdset: Union[CommandSet, 'Cmd']) -> None:
957957
command_func = self.cmd_func(command_name)
958958

959959
if command_func is None:
960-
raise CommandSetRegistrationError(
961-
f"Could not find command '{command_name}' needed by subcommand: {str(method)}"
962-
)
960+
raise CommandSetRegistrationError(f"Could not find command '{command_name}' needed by subcommand: {method!s}")
963961
command_parser = self._command_parsers.get(command_func)
964962
if command_parser is None:
965963
raise CommandSetRegistrationError(
966-
f"Could not find argparser for command '{command_name}' needed by subcommand: {str(method)}"
964+
f"Could not find argparser for command '{command_name}' needed by subcommand: {method!s}"
967965
)
968966

969967
def find_subcommand(action: argparse.ArgumentParser, subcmd_names: List[str]) -> argparse.ArgumentParser:
@@ -1059,15 +1057,13 @@ def _unregister_subcommands(self, cmdset: Union[CommandSet, 'Cmd']) -> None:
10591057
if command_func is None: # pragma: no cover
10601058
# This really shouldn't be possible since _register_subcommands would prevent this from happening
10611059
# but keeping in case it does for some strange reason
1062-
raise CommandSetRegistrationError(
1063-
f"Could not find command '{command_name}' needed by subcommand: {str(method)}"
1064-
)
1060+
raise CommandSetRegistrationError(f"Could not find command '{command_name}' needed by subcommand: {method!s}")
10651061
command_parser = self._command_parsers.get(command_func)
10661062
if command_parser is None: # pragma: no cover
10671063
# This really shouldn't be possible since _register_subcommands would prevent this from happening
10681064
# but keeping in case it does for some strange reason
10691065
raise CommandSetRegistrationError(
1070-
f"Could not find argparser for command '{command_name}' needed by subcommand: {str(method)}"
1066+
f"Could not find argparser for command '{command_name}' needed by subcommand: {method!s}"
10711067
)
10721068

10731069
for action in command_parser._actions:

cmd2/parsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def is_valid_command(self, word: str, *, is_subcommand: bool = False) -> Tuple[b
340340
valid = False
341341

342342
if not isinstance(word, str):
343-
return False, f'must be a string. Received {str(type(word))} instead' # type: ignore[unreachable]
343+
return False, f'must be a string. Received {type(word)!s} instead' # type: ignore[unreachable]
344344

345345
if not word:
346346
return False, 'cannot be an empty string'

examples/modular_commands_main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from modular_commands.commandset_complex import ( # noqa: F401
1919
CommandSetA,
2020
)
21-
from modular_commands.commandset_custominit import ( # noqa: F401
21+
from modular_commands.commandset_custominit import (
2222
CustomInitCommandSet,
2323
)
2424

0 commit comments

Comments
 (0)