Skip to content

Commit b697356

Browse files
authored
Enable ruff ARG ruleset to warn about unused arguments (#1425)
1 parent e68746b commit b697356

20 files changed

+49
-41
lines changed

cmd2/argparse_custom.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ class CompletionItem(str): # noqa: SLOT000
280280
See header of this file for more information
281281
"""
282282

283-
def __new__(cls, value: object, *args: Any, **kwargs: Any) -> 'CompletionItem':
283+
def __new__(cls, value: object, *_args: Any, **_kwargs: Any) -> 'CompletionItem':
284284
return super().__new__(cls, value)
285285

286286
def __init__(self, value: object, description: str = '', *args: Any) -> None:
@@ -914,7 +914,7 @@ def _ArgumentParser_set_ap_completer_type(self: argparse.ArgumentParser, ap_comp
914914
############################################################################################################
915915
# Patch ArgumentParser._check_value to support CompletionItems as choices
916916
############################################################################################################
917-
def _ArgumentParser_check_value(self: argparse.ArgumentParser, action: argparse.Action, value: Any) -> None: # noqa: N802
917+
def _ArgumentParser_check_value(_self: argparse.ArgumentParser, action: argparse.Action, value: Any) -> None: # noqa: N802
918918
"""Custom override of ArgumentParser._check_value that supports CompletionItems as choices.
919919
When evaluating choices, input is compared to CompletionItem.orig_value instead of the
920920
CompletionItem instance.

cmd2/cmd2.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ def remove_settable(self, name: str) -> None:
11111111
def build_settables(self) -> None:
11121112
"""Create the dictionary of user-settable parameters."""
11131113

1114-
def get_allow_style_choices(cli_self: Cmd) -> list[str]:
1114+
def get_allow_style_choices(_cli_self: Cmd) -> list[str]:
11151115
"""Used to tab complete allow_style values."""
11161116
return [val.name.lower() for val in ansi.AllowStyle]
11171117

@@ -1419,9 +1419,9 @@ def tokens_for_completion(self, line: str, begidx: int, endidx: int) -> tuple[li
14191419
def basic_complete(
14201420
self,
14211421
text: str,
1422-
line: str,
1423-
begidx: int,
1424-
endidx: int,
1422+
line: str, # noqa: ARG002
1423+
begidx: int, # noqa: ARG002
1424+
endidx: int, # noqa: ARG002
14251425
match_against: Iterable[str],
14261426
) -> list[str]:
14271427
"""Basic tab completion function that matches against a list of strings without considering line contents
@@ -1602,7 +1602,13 @@ def index_based_complete(
16021602
return matches
16031603

16041604
def path_complete(
1605-
self, text: str, line: str, begidx: int, endidx: int, *, path_filter: Optional[Callable[[str], bool]] = None
1605+
self,
1606+
text: str,
1607+
line: str,
1608+
begidx: int, # noqa: ARG002
1609+
endidx: int,
1610+
*,
1611+
path_filter: Optional[Callable[[str], bool]] = None,
16061612
) -> list[str]:
16071613
"""Performs completion of local file system paths.
16081614
@@ -2346,7 +2352,7 @@ def get_help_topics(self) -> list[str]:
23462352
# Filter out hidden and disabled commands
23472353
return [topic for topic in all_topics if topic not in self.hidden_commands and topic not in self.disabled_commands]
23482354

2349-
def sigint_handler(self, signum: int, _: Optional[FrameType]) -> None:
2355+
def sigint_handler(self, signum: int, _: Optional[FrameType]) -> None: # noqa: ARG002
23502356
"""Signal handler for SIGINTs which typically come from Ctrl-C events.
23512357
23522358
If you need custom SIGINT behavior, then override this method.
@@ -2402,7 +2408,7 @@ def precmd(self, statement: Union[Statement, str]) -> Statement:
24022408
"""
24032409
return Statement(statement) if not isinstance(statement, Statement) else statement
24042410

2405-
def postcmd(self, stop: bool, statement: Union[Statement, str]) -> bool:
2411+
def postcmd(self, stop: bool, statement: Union[Statement, str]) -> bool: # noqa: ARG002
24062412
"""Hook method executed just after a command is executed by
24072413
[cmd2.Cmd.onecmd][].
24082414
@@ -3087,7 +3093,7 @@ def configure_readline() -> None:
30873093
# Disable completion
30883094
if completion_mode == utils.CompletionMode.NONE:
30893095

3090-
def complete_none(text: str, state: int) -> Optional[str]: # pragma: no cover
3096+
def complete_none(text: str, state: int) -> Optional[str]: # pragma: no cover # noqa: ARG001
30913097
return None
30923098

30933099
complete_func = complete_none
@@ -3773,7 +3779,7 @@ def do_help(self, args: argparse.Namespace) -> None:
37733779
self.perror(err_msg, apply_style=False)
37743780
self.last_result = False
37753781

3776-
def print_topics(self, header: str, cmds: Optional[list[str]], cmdlen: int, maxcol: int) -> None:
3782+
def print_topics(self, header: str, cmds: Optional[list[str]], cmdlen: int, maxcol: int) -> None: # noqa: ARG002
37773783
"""Print groups of commands and topics in columns and an optional header
37783784
Override of cmd's print_topics() to handle headers with newlines, ANSI style sequences, and wide characters.
37793785
@@ -5379,7 +5385,7 @@ def disable_command(self, command: str, message_to_print: str) -> None:
53795385
setattr(self, help_func_name, new_func)
53805386

53815387
# Set the completer to a function that returns a blank list
5382-
setattr(self, completer_func_name, lambda *args, **kwargs: [])
5388+
setattr(self, completer_func_name, lambda *_args, **_kwargs: [])
53835389

53845390
def disable_category(self, category: str, message_to_print: str) -> None:
53855391
"""Disable an entire category of commands.

cmd2/parsing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ class Statement(str): # type: ignore[override] # noqa: SLOT000
145145
# Used in JSON dictionaries
146146
_args_field = 'args'
147147

148-
def __new__(cls, value: object, *pos_args: Any, **kw_args: Any) -> 'Statement':
148+
def __new__(cls, value: object, *_pos_args: Any, **_kw_args: Any) -> 'Statement':
149149
"""Create a new instance of Statement.
150150
151151
We must override __new__ because we are subclassing `str` which is

examples/basic_completion.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def do_raise_error(self, statement: cmd2.Statement) -> None:
8282
"""Demonstrates effect of raising CompletionError."""
8383
self.poutput(f"Args: {statement.args}")
8484

85-
def complete_raise_error(self, text, line, begidx, endidx) -> list[str]:
85+
def complete_raise_error(self, _text, _line, _begidx, _endidx) -> list[str]:
8686
"""CompletionErrors can be raised if an error occurs while tab completing.
8787
8888
Example use cases

examples/default_categories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class ExampleApp(cmd2.Cmd):
6767
def __init__(self) -> None:
6868
super().__init__()
6969

70-
def do_something(self, arg) -> None:
70+
def do_something(self, _arg) -> None:
7171
self.poutput('this is the something command')
7272

7373

examples/dynamic_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self) -> None:
3434

3535
super().__init__(include_ipy=True)
3636

37-
def send_text(self, args: cmd2.Statement, *, text: str) -> None:
37+
def send_text(self, _args: cmd2.Statement, *, text: str) -> None:
3838
"""Simulate sending text to a server and printing the response."""
3939
self.poutput(text.capitalize())
4040

examples/environment.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def __init__(self) -> None:
1616
)
1717
self.add_settable(cmd2.Settable('sunny', bool, 'Is it sunny outside?', self))
1818

19-
def do_sunbathe(self, arg) -> None:
19+
def do_sunbathe(self, _arg) -> None:
2020
"""Attempt to sunbathe."""
2121
if self.degrees_c < 20:
2222
result = f"It's {self.degrees_c} C - are you a penguin?"
@@ -26,7 +26,7 @@ def do_sunbathe(self, arg) -> None:
2626
result = 'UV is bad for your skin.'
2727
self.poutput(result)
2828

29-
def _onchange_degrees_c(self, param_name, old, new) -> None:
29+
def _onchange_degrees_c(self, _param_name, _old, new) -> None:
3030
# if it's over 40C, it's gotta be sunny, right?
3131
if new > 40:
3232
self.sunny = True

examples/migrating.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class CmdLineApp(cmd.Cmd):
1313
MUMBLE_FIRST = ('so', 'like', 'well')
1414
MUMBLE_LAST = ('right?',)
1515

16-
def do_exit(self, line) -> bool:
16+
def do_exit(self, _line) -> bool:
1717
"""Exit the application."""
1818
return True
1919

examples/modular_commands/commandset_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def do_raise_error(self, statement: Statement) -> None:
7373
"""Demonstrates effect of raising CompletionError."""
7474
self._cmd.poutput(f"Args: {statement.args}")
7575

76-
def complete_raise_error(self, text: str, line: str, begidx: int, endidx: int) -> list[str]:
76+
def complete_raise_error(self, _text: str, _line: str, _begidx: int, _endidx: int) -> list[str]:
7777
"""CompletionErrors can be raised if an error occurs while tab completing.
7878
7979
Example use cases
@@ -83,5 +83,5 @@ def complete_raise_error(self, text: str, line: str, begidx: int, endidx: int) -
8383
raise CompletionError("This is how a CompletionError behaves")
8484

8585
@with_category('Not Basic Completion')
86-
def do_custom_category(self, statement: Statement) -> None:
86+
def do_custom_category(self, _statement: Statement) -> None:
8787
self._cmd.poutput('Demonstrates a command that bypasses the default category')

examples/modular_commands/commandset_complex.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77

88
@cmd2.with_default_category('Fruits')
99
class CommandSetA(cmd2.CommandSet):
10-
def do_apple(self, statement: cmd2.Statement) -> None:
10+
def do_apple(self, _statement: cmd2.Statement) -> None:
1111
self._cmd.poutput('Apple!')
1212

13-
def do_banana(self, statement: cmd2.Statement) -> None:
13+
def do_banana(self, _statement: cmd2.Statement) -> None:
1414
"""Banana Command."""
1515
self._cmd.poutput('Banana!!')
1616

0 commit comments

Comments
 (0)