Skip to content

Commit abb8579

Browse files
committed
Applied some list performance optimizations from ruff RUF ruleset
1 parent 29e64d6 commit abb8579

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

cmd2/argparse_custom.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,14 +1078,14 @@ def get_lines(parts: list[str], indent: str, prefix: Optional[str] = None) -> li
10781078
indent = ' ' * (len(prefix) + len(prog) + 1)
10791079
# Begin cmd2 customization
10801080
if req_parts:
1081-
lines = get_lines([prog] + req_parts, indent, prefix)
1081+
lines = get_lines([prog, *req_parts], indent, prefix)
10821082
lines.extend(get_lines(opt_parts, indent))
10831083
lines.extend(get_lines(pos_parts, indent))
10841084
elif opt_parts:
1085-
lines = get_lines([prog] + opt_parts, indent, prefix)
1085+
lines = get_lines([prog, *opt_parts], indent, prefix)
10861086
lines.extend(get_lines(pos_parts, indent))
10871087
elif pos_parts:
1088-
lines = get_lines([prog] + pos_parts, indent, prefix)
1088+
lines = get_lines([prog, *pos_parts], indent, prefix)
10891089
else:
10901090
lines = [prog]
10911091
# End cmd2 customization
@@ -1102,7 +1102,7 @@ def get_lines(parts: list[str], indent: str, prefix: Optional[str] = None) -> li
11021102
lines.extend(get_lines(opt_parts, indent))
11031103
lines.extend(get_lines(pos_parts, indent))
11041104
# End cmd2 customization
1105-
lines = [prog] + lines
1105+
lines = [prog, *lines]
11061106

11071107
# join lines into usage
11081108
usage = '\n'.join(lines)

cmd2/cmd2.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4224,7 +4224,7 @@ def do_shell(self, args: argparse.Namespace) -> None:
42244224
kwargs['executable'] = shell
42254225

42264226
# Create a list of arguments to shell
4227-
tokens = [args.command] + args.command_args
4227+
tokens = [args.command, *args.command_args]
42284228

42294229
# Expand ~ where needed
42304230
utils.expand_user_in_tokens(tokens)
@@ -4530,7 +4530,7 @@ def do_run_pyscript(self, args: argparse.Namespace) -> Optional[bool]:
45304530

45314531
try:
45324532
# Overwrite sys.argv to allow the script to take command line arguments
4533-
sys.argv = [args.script_path] + args.script_arguments
4533+
sys.argv = [args.script_path, *args.script_arguments]
45344534

45354535
# self.last_resort will be set by _run_python()
45364536
py_return = self._run_python(pyscript=args.script_path)
@@ -5562,7 +5562,7 @@ def _validate_postparsing_callable(cls, func: Callable[[plugin.PostparsingData],
55625562
"""Check parameter and return types for postparsing hooks"""
55635563
cls._validate_callable_param_count(cast(Callable[..., Any], func), 1)
55645564
signature = inspect.signature(func)
5565-
_, param = list(signature.parameters.items())[0]
5565+
_, param = next(iter(signature.parameters.items()))
55665566
if param.annotation != plugin.PostparsingData:
55675567
raise TypeError(f"{func.__name__} must have one parameter declared with type 'cmd2.plugin.PostparsingData'")
55685568
if signature.return_annotation != plugin.PostparsingData:
@@ -5584,7 +5584,7 @@ def _validate_prepostcmd_hook(
55845584
# validate that the callable has the right number of parameters
55855585
cls._validate_callable_param_count(cast(Callable[..., Any], func), 1)
55865586
# validate the parameter has the right annotation
5587-
paramname = list(signature.parameters.keys())[0]
5587+
paramname = next(iter(signature.parameters.keys()))
55885588
param = signature.parameters[paramname]
55895589
if param.annotation != data_type:
55905590
raise TypeError(f'argument 1 of {func.__name__} has incompatible type {param.annotation}, expected {data_type}')
@@ -5613,7 +5613,7 @@ def _validate_cmdfinalization_callable(
56135613
"""Check parameter and return types for command finalization hooks."""
56145614
cls._validate_callable_param_count(func, 1)
56155615
signature = inspect.signature(func)
5616-
_, param = list(signature.parameters.items())[0]
5616+
_, param = next(iter(signature.parameters.items()))
56175617
if param.annotation != plugin.CommandFinalizationData:
56185618
raise TypeError(f"{func.__name__} must have one parameter declared with type {plugin.CommandFinalizationData}")
56195619
if signature.return_annotation != plugin.CommandFinalizationData:

0 commit comments

Comments
 (0)