Skip to content

Commit

Permalink
The latest version of Ruff has some improved string formatting, run a…
Browse files Browse the repository at this point in the history
…uto-format to fix that
  • Loading branch information
tleonhardt committed Jan 15, 2025
1 parent dac5891 commit 96a5cad
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
7 changes: 3 additions & 4 deletions cmd2/argparse_custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,12 +477,11 @@ def _action_set_choices_callable(self: argparse.Action, choices_callable: Choice
"""
# Verify consistent use of parameters
if self.choices is not None:
err_msg = "None of the following parameters can be used alongside a choices parameter:\n" "choices_provider, completer"
err_msg = "None of the following parameters can be used alongside a choices parameter:\nchoices_provider, completer"
raise (TypeError(err_msg))
elif self.nargs == 0:
err_msg = (
"None of the following parameters can be used on an action that takes no arguments:\n"
"choices_provider, completer"
"None of the following parameters can be used on an action that takes no arguments:\nchoices_provider, completer"
)
raise (TypeError(err_msg))

Expand Down Expand Up @@ -766,7 +765,7 @@ def _add_argument_wrapper(
num_params_set = len(choices_callables) - choices_callables.count(None)

if num_params_set > 1:
err_msg = "Only one of the following parameters may be used at a time:\n" "choices_provider, completer"
err_msg = "Only one of the following parameters may be used at a time:\nchoices_provider, completer"
raise (ValueError(err_msg))

# Pre-process special ranged nargs
Expand Down
24 changes: 12 additions & 12 deletions cmd2/cmd2.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ class Cmd(cmd.Cmd):
DEFAULT_EDITOR = utils.find_editor()

INTERNAL_COMMAND_EPILOG = (
"Notes:\n" " This command is for internal use and is not intended to be called from the\n" " command line."
"Notes:\n This command is for internal use and is not intended to be called from the\n command line."
)

# Sorting keys for strings
Expand Down Expand Up @@ -3380,8 +3380,8 @@ def _cmdloop(self) -> None:
#############################################################

# Top-level parser for alias
alias_description = "Manage aliases\n" "\n" "An alias is a command that enables replacement of a word by another string."
alias_epilog = "See also:\n" " macro"
alias_description = "Manage aliases\n\nAn alias is a command that enables replacement of a word by another string."
alias_epilog = "See also:\n macro"
alias_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description=alias_description, epilog=alias_epilog)
alias_parser.add_subparsers(metavar='SUBCOMMAND', required=True)

Expand Down Expand Up @@ -3548,8 +3548,8 @@ def _alias_list(self, args: argparse.Namespace) -> None:
#############################################################

# Top-level parser for macro
macro_description = "Manage macros\n" "\n" "A macro is similar to an alias, but it can contain argument placeholders."
macro_epilog = "See also:\n" " alias"
macro_description = "Manage macros\n\nA macro is similar to an alias, but it can contain argument placeholders."
macro_epilog = "See also:\n alias"
macro_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(description=macro_description, epilog=macro_epilog)
macro_parser.add_subparsers(metavar='SUBCOMMAND', required=True)

Expand Down Expand Up @@ -3806,7 +3806,7 @@ def complete_help_subcommands(
return completer.complete_subcommand_help(text, line, begidx, endidx, arg_tokens['subcommands'])

help_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(
description="List available commands or provide " "detailed help for a specific command"
description="List available commands or provide detailed help for a specific command"
)
help_parser.add_argument(
'-v', '--verbose', action='store_true', help="print a list of all commands with descriptions of each"
Expand Down Expand Up @@ -4699,22 +4699,22 @@ def do_ipy(self, _: argparse.Namespace) -> Optional[bool]: # pragma: no cover

history_format_group = history_parser.add_argument_group(title='formatting')
history_format_group.add_argument(
'-s', '--script', action='store_true', help='output commands in script format, i.e. without command\n' 'numbers'
'-s', '--script', action='store_true', help='output commands in script format, i.e. without command\nnumbers'
)
history_format_group.add_argument(
'-x',
'--expanded',
action='store_true',
help='output fully parsed commands with any aliases and\n' 'macros expanded, instead of typed commands',
help='output fully parsed commands with any aliases and\nmacros expanded, instead of typed commands',
)
history_format_group.add_argument(
'-v',
'--verbose',
action='store_true',
help='display history and include expanded commands if they\n' 'differ from the typed command',
help='display history and include expanded commands if they\ndiffer from the typed command',
)
history_format_group.add_argument(
'-a', '--all', action='store_true', help='display all commands, including ones persisted from\n' 'previous sessions'
'-a', '--all', action='store_true', help='display all commands, including ones persisted from\nprevious sessions'
)

history_arg_help = (
Expand Down Expand Up @@ -5189,7 +5189,7 @@ def do_run_script(self, args: argparse.Namespace) -> Optional[bool]:
"interpreted relative to the already-running script's directory."
)

relative_run_script_epilog = "Notes:\n" " This command is intended to only be used within text file scripts."
relative_run_script_epilog = "Notes:\n This command is intended to only be used within text file scripts."

relative_run_script_parser = argparse_custom.DEFAULT_ARGUMENT_PARSER(
description=relative_run_script_description, epilog=relative_run_script_epilog
Expand Down Expand Up @@ -5671,7 +5671,7 @@ def _validate_prepostcmd_hook(
raise TypeError(f'{func.__name__} does not have a declared return type, expected {data_type}')
if signature.return_annotation != data_type:
raise TypeError(
f'{func.__name__} has incompatible return type {signature.return_annotation}, expected ' f'{data_type}'
f'{func.__name__} has incompatible return type {signature.return_annotation}, expected {data_type}'
)

def register_precmd_hook(self, func: Callable[[plugin.PrecommandData], plugin.PrecommandData]) -> None:
Expand Down
2 changes: 1 addition & 1 deletion examples/argparse_completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def choices_arg_tokens(self, arg_tokens: Dict[str, List[str]]) -> List[str]:

# Parser for example command
example_parser = Cmd2ArgumentParser(
description="Command demonstrating tab completion with argparse\n" "Notice even the flags of this command tab complete"
description="Command demonstrating tab completion with argparse\nNotice even the flags of this command tab complete"
)

# Tab complete from a list using argparse choices. Set metavar if you don't
Expand Down
2 changes: 1 addition & 1 deletion examples/modular_commands_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def choices_provider(self) -> List[str]:

# Parser for example command
example_parser = Cmd2ArgumentParser(
description="Command demonstrating tab completion with argparse\n" "Notice even the flags of this command tab complete"
description="Command demonstrating tab completion with argparse\nNotice even the flags of this command tab complete"
)

# Tab complete from a list using argparse choices. Set metavar if you don't
Expand Down
6 changes: 3 additions & 3 deletions examples/table_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ def basic_tables():

# Table data which demonstrates handling of wrapping and text styles
data_list: List[List[Any]] = list()
data_list.append(["Billy Smith", "123 Sesame St.\n" "Fake Town, USA 33445", DollarFormatter(100333.03)])
data_list.append(["Billy Smith", "123 Sesame St.\nFake Town, USA 33445", DollarFormatter(100333.03)])
data_list.append(
[
"William Longfellow Marmaduke III",
"984 Really Long Street Name Which Will Wrap Nicely\n" "Apt 22G\n" "Pensacola, FL 32501",
"984 Really Long Street Name Which Will Wrap Nicely\nApt 22G\nPensacola, FL 32501",
DollarFormatter(55135.22),
]
)
data_list.append(
[
"James " + blue("Bluestone"),
bold_yellow("This address has line feeds,\n" "text styles, and wrapping. ")
bold_yellow("This address has line feeds,\ntext styles, and wrapping. ")
+ blue("Style is preserved across lines."),
DollarFormatter(300876.10),
]
Expand Down

0 comments on commit 96a5cad

Please sign in to comment.