Skip to content

Commit 161eb00

Browse files
committed
Run black.
1 parent ae7c087 commit 161eb00

2 files changed

Lines changed: 171 additions & 80 deletions

File tree

flake8_unused_arguments.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ def visit_Name(self, name: ast.Name) -> None:
107107
if isinstance(name.ctx, Store):
108108
return
109109

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

112114
NameFinder().visit(function)
113115

test_unused_arguments.py

Lines changed: 168 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -7,26 +7,38 @@
77
import pytest
88

99

10-
@pytest.mark.parametrize("function, expected_names", [
11-
("def foo(a, b, c): pass", ["a", "b", "c"]),
12-
("def foo(a, b, *, c): pass", ["a", "b", "c"]),
13-
("def foo(a, b, *, c=5): pass", ["a", "b", "c"]),
14-
("def foo(*args): pass", ["args"]),
15-
("def foo(**kwargs): pass", ["kwargs"]),
16-
("def foo(a, b, *args, c, d=5, e, **kwargs): pass", ["a", "b", "args", "c", "d", "e", "kwargs"]),
17-
("async def foo(a, b, c): pass", ["a", "b", "c"]),
18-
("async def foo(a, b, *, c): pass", ["a", "b", "c"]),
19-
("async def foo(a, b, *, c=5): pass", ["a", "b", "c"]),
20-
("async def foo(*args): pass", ["args"]),
21-
("async def foo(**kwargs): pass", ["kwargs"]),
22-
("async def foo(a, b, *args, c, d=5, e, **kwargs): pass", ["a", "b", "args", "c", "d", "e", "kwargs"]),
23-
("""
10+
@pytest.mark.parametrize(
11+
"function, expected_names",
12+
[
13+
("def foo(a, b, c): pass", ["a", "b", "c"]),
14+
("def foo(a, b, *, c): pass", ["a", "b", "c"]),
15+
("def foo(a, b, *, c=5): pass", ["a", "b", "c"]),
16+
("def foo(*args): pass", ["args"]),
17+
("def foo(**kwargs): pass", ["kwargs"]),
18+
(
19+
"def foo(a, b, *args, c, d=5, e, **kwargs): pass",
20+
["a", "b", "args", "c", "d", "e", "kwargs"],
21+
),
22+
("async def foo(a, b, c): pass", ["a", "b", "c"]),
23+
("async def foo(a, b, *, c): pass", ["a", "b", "c"]),
24+
("async def foo(a, b, *, c=5): pass", ["a", "b", "c"]),
25+
("async def foo(*args): pass", ["args"]),
26+
("async def foo(**kwargs): pass", ["kwargs"]),
27+
(
28+
"async def foo(a, b, *args, c, d=5, e, **kwargs): pass",
29+
["a", "b", "args", "c", "d", "e", "kwargs"],
30+
),
31+
(
32+
"""
2433
class foo:
2534
def bar(self, cool):
2635
pass
27-
""", ["self", "cool"]),
28-
("l = lambda g: 5", ["g"]),
29-
])
36+
""",
37+
["self", "cool"],
38+
),
39+
("l = lambda g: 5", ["g"]),
40+
],
41+
)
3042
def test_get_argument_names(function, expected_names):
3143
from flake8_unused_arguments import get_arguments
3244

@@ -36,20 +48,29 @@ def test_get_argument_names(function, expected_names):
3648
assert argument_names == expected_names
3749

3850

39-
@pytest.mark.parametrize("function, expected_names", [
40-
("def foo(a, b, c): return a + b", ["c"]),
41-
("""
51+
@pytest.mark.parametrize(
52+
"function, expected_names",
53+
[
54+
("def foo(a, b, c): return a + b", ["c"]),
55+
(
56+
"""
4257
class foo:
4358
def bar(self, cool):
4459
self.thing = cool
45-
""", []),
46-
("""
60+
""",
61+
[],
62+
),
63+
(
64+
"""
4765
def external(a, b, c):
4866
def internal():
4967
a + b
50-
""", ["c"]),
51-
("l = lambda g: 5", ["g"]),
52-
])
68+
""",
69+
["c"],
70+
),
71+
("l = lambda g: 5", ["g"]),
72+
],
73+
)
5374
def test_get_unused_arguments(function, expected_names):
5475
from flake8_unused_arguments import get_unused_arguments
5576

@@ -59,114 +80,181 @@ def test_get_unused_arguments(function, expected_names):
5980
assert argument_names == expected_names
6081

6182

62-
@pytest.mark.parametrize("function, expected_result", [
63-
("""
83+
@pytest.mark.parametrize(
84+
"function, expected_result",
85+
[
86+
(
87+
"""
6488
@a
6589
@thing.b
6690
@thing.c()
6791
@d()
6892
def foo():
6993
pass
70-
""", ["a", "b", "c", "d"]),
71-
("lambda g: 5", []),
72-
])
94+
""",
95+
["a", "b", "c", "d"],
96+
),
97+
("lambda g: 5", []),
98+
],
99+
)
73100
def test_get_decorator_names(function, expected_result):
74101
from flake8_unused_arguments import get_decorator_names
75102

76103
function_names = list(get_decorator_names(get_function(function)))
77104
assert function_names == expected_result
78105

79106

80-
@pytest.mark.parametrize("function, expected_result", [
81-
("def foo():\n 'with docstring'\n pass", True),
82-
("def foo():\n 'with docstring'", True),
83-
("def foo():\n 'with docstring'\n ...", True),
84-
("def foo():\n 'with docstring'\n return 5", False),
85-
("def foo():\n 'string' + 'with docstring'\n ...", False),
86-
("def foo():\n f = 'string' + 'with docstring'\n ...", False),
87-
("def foo(): pass", True),
88-
("def foo(): ...", True),
89-
("def foo(): return 5", False),
90-
("def foo(): raise NotImplementedError()", True),
91-
("def foo(): raise NotImplementedError", True),
92-
("def foo(): raise NotImplementedError()", True),
93-
("def foo(): raise NotImplementedError", True),
94-
("def foo(): raise SomethingElse()", False),
95-
("def foo(): raise", False),
96-
("lambda: ...", True),
97-
("lambda: 5", False),
98-
("""
107+
@pytest.mark.parametrize(
108+
"function, expected_result",
109+
[
110+
("def foo():\n 'with docstring'\n pass", True),
111+
("def foo():\n 'with docstring'", True),
112+
("def foo():\n 'with docstring'\n ...", True),
113+
("def foo():\n 'with docstring'\n return 5", False),
114+
("def foo():\n 'string' + 'with docstring'\n ...", False),
115+
("def foo():\n f = 'string' + 'with docstring'\n ...", False),
116+
("def foo(): pass", True),
117+
("def foo(): ...", True),
118+
("def foo(): return 5", False),
119+
("def foo(): raise NotImplementedError()", True),
120+
("def foo(): raise NotImplementedError", True),
121+
("def foo(): raise NotImplementedError()", True),
122+
("def foo(): raise NotImplementedError", True),
123+
("def foo(): raise SomethingElse()", False),
124+
("def foo(): raise", False),
125+
("lambda: ...", True),
126+
("lambda: 5", False),
127+
(
128+
"""
99129
def foo():
100130
a = 5
101131
return 5
102-
""", False),
103-
("""
132+
""",
133+
False,
134+
),
135+
(
136+
"""
104137
def foo():
105138
if 5:
106139
return
107140
else:
108141
return
109-
""", False),
110-
])
142+
""",
143+
False,
144+
),
145+
],
146+
)
111147
def test_is_stub_function(function, expected_result):
112148
from flake8_unused_arguments import is_stub_function
149+
113150
assert is_stub_function(get_function(function)) == expected_result
114151

115152

116-
@pytest.mark.parametrize("function, options, expected_warnings", [
117-
("""
153+
@pytest.mark.parametrize(
154+
"function, options, expected_warnings",
155+
[
156+
(
157+
"""
118158
@abstractmethod
119159
def foo(a):
120160
pass
121-
""", {"ignore_abstract": False}, [(3, 8, "U100 Unused argument 'a'", 'unused argument')]),
122-
("""
161+
""",
162+
{"ignore_abstract": False},
163+
[(3, 8, "U100 Unused argument 'a'", "unused argument")],
164+
),
165+
(
166+
"""
123167
@abstractmethod
124168
def foo(a):
125169
pass
126-
""", {"ignore_abstract": True}, []),
127-
("""
170+
""",
171+
{"ignore_abstract": True},
172+
[],
173+
),
174+
(
175+
"""
128176
def foo(a):
129177
pass
130-
""", {"ignore_stubs": False}, [(2, 8, "U100 Unused argument 'a'", 'unused argument')]),
131-
("""
178+
""",
179+
{"ignore_stubs": False},
180+
[(2, 8, "U100 Unused argument 'a'", "unused argument")],
181+
),
182+
(
183+
"""
132184
def foo(a):
133185
pass
134-
""", {"ignore_stubs": True}, []),
135-
("""
186+
""",
187+
{"ignore_stubs": True},
188+
[],
189+
),
190+
(
191+
"""
136192
def foo(*args):
137193
pass
138-
""", {"ignore_variadic_names": True}, []),
139-
("""
194+
""",
195+
{"ignore_variadic_names": True},
196+
[],
197+
),
198+
(
199+
"""
140200
def foo(**kwargs):
141201
pass
142-
""", {"ignore_variadic_names": True}, []),
143-
("""
202+
""",
203+
{"ignore_variadic_names": True},
204+
[],
205+
),
206+
(
207+
"""
144208
def foo(*args):
145209
pass
146-
""", {"ignore_variadic_names": False}, [(2, 9, "U100 Unused argument 'args'", 'unused argument')]),
147-
("""
210+
""",
211+
{"ignore_variadic_names": False},
212+
[(2, 9, "U100 Unused argument 'args'", "unused argument")],
213+
),
214+
(
215+
"""
148216
def foo(**kwargs):
149217
pass
150-
""", {"ignore_variadic_names": False}, [(2, 10, "U100 Unused argument 'kwargs'", 'unused argument')]),
151-
("""
218+
""",
219+
{"ignore_variadic_names": False},
220+
[(2, 10, "U100 Unused argument 'kwargs'", "unused argument")],
221+
),
222+
(
223+
"""
152224
def foo(_a):
153225
pass
154-
""", {}, [(2, 8, "U101 Unused argument '_a'", 'unused argument')]),
155-
("""
226+
""",
227+
{},
228+
[(2, 8, "U101 Unused argument '_a'", "unused argument")],
229+
),
230+
(
231+
"""
156232
def foo(self):
157233
pass
158-
""", {}, []),
159-
("""
234+
""",
235+
{},
236+
[],
237+
),
238+
(
239+
"""
160240
@classmethod
161241
def foo(cls):
162242
pass
163-
""", {}, []),
164-
("""
243+
""",
244+
{},
245+
[],
246+
),
247+
(
248+
"""
165249
@classmethod
166250
def foo(cls, bar):
167251
use(cls)
168-
""", {}, [(3, 13, "U100 Unused argument 'bar'", 'unused argument')]),
169-
])
252+
""",
253+
{},
254+
[(3, 13, "U100 Unused argument 'bar'", "unused argument")],
255+
),
256+
],
257+
)
170258
def test_integration(function, options, expected_warnings):
171259
from flake8_unused_arguments import Plugin
172260

@@ -194,6 +282,7 @@ def get_most_recent_tag() -> str:
194282

195283
def get_function(text):
196284
from flake8_unused_arguments import FunctionFinder
285+
197286
finder = FunctionFinder()
198287
finder.visit(ast.parse(textwrap.dedent(text)))
199288
return finder.functions[0]

0 commit comments

Comments
 (0)