Skip to content

Commit 4858efb

Browse files
committed
Fix ignoring first unused argument in classmethods.
1 parent c54368d commit 4858efb

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

flake8_unused_arguments.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def run(self) -> Iterable[LintResult]:
7070
if self.ignore_stubs and is_stub_function(function):
7171
continue
7272

73-
for i, argument in enumerate(get_unused_arguments(function)):
73+
for i, argument in get_unused_arguments(function):
7474
name = argument.arg
7575
if self.ignore_variadic_names:
7676
if function.args.vararg and function.args.vararg.arg == name:
@@ -97,17 +97,17 @@ def run(self) -> Iterable[LintResult]:
9797
yield (line_number, offset, text, check)
9898

9999

100-
def get_unused_arguments(function: FunctionTypes) -> List[ast.arg]:
100+
def get_unused_arguments(function: FunctionTypes) -> List[Tuple[int, ast.arg]]:
101101
"""Generator that yields all of the unused arguments in the given function."""
102-
arguments = get_arguments(function)
102+
arguments = list(enumerate(get_arguments(function)))
103103

104104
class NameFinder(NodeVisitor):
105105
def visit_Name(self, name: ast.Name) -> None:
106106
nonlocal arguments
107107
if isinstance(name.ctx, Store):
108108
return
109109

110-
arguments = [arg for arg in arguments if arg.arg != name.id]
110+
arguments = [(arg_index, arg) for arg_index, arg in arguments if arg.arg != name.id]
111111

112112
NameFinder().visit(function)
113113

test_unused_arguments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def internal():
5252
def test_get_unused_arguments(function, expected_names):
5353
from flake8_unused_arguments import get_unused_arguments
5454

55-
argument_names = [a.arg for a in get_unused_arguments(get_function(function))]
55+
argument_names = [a.arg for _, a in get_unused_arguments(get_function(function))]
5656
print(argument_names)
5757
print(expected_names)
5858
assert argument_names == expected_names

0 commit comments

Comments
 (0)