Skip to content

Commit 2e3e5a8

Browse files
charliermarshpull[bot]
authored andcommitted
Ignore unused arguments for @overload stubs (#1373)
1 parent a9e8e3a commit 2e3e5a8

7 files changed

+54
-32
lines changed

resources/test/fixtures/flake8_unused_arguments/ARG.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from abc import abstractmethod
2+
from typing import overload
23
from typing_extensions import override
34

45

@@ -135,3 +136,20 @@ def f(cls, x):
135136
@override
136137
def f(x):
137138
print("Hello, world!")
139+
140+
141+
###
142+
# Unused arguments attached to overloads (OK).
143+
###
144+
@overload
145+
def f(a: str, b: str) -> str:
146+
...
147+
148+
149+
@overload
150+
def f(a: int, b: int) -> str:
151+
...
152+
153+
154+
def f(a, b):
155+
return f"{a}{b}"

src/flake8_unused_arguments/plugins.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ pub fn unused_arguments(
130130
.settings
131131
.enabled
132132
.contains(Argumentable::Function.check_code())
133+
&& !visibility::is_overload(checker, decorator_list)
133134
{
134135
function(
135136
&Argumentable::Function,
@@ -154,6 +155,7 @@ pub fn unused_arguments(
154155
&& !helpers::is_empty(body)
155156
&& !visibility::is_abstract(checker, decorator_list)
156157
&& !visibility::is_override(checker, decorator_list)
158+
&& !visibility::is_overload(checker, decorator_list)
157159
{
158160
method(
159161
&Argumentable::Method,
@@ -178,6 +180,7 @@ pub fn unused_arguments(
178180
&& !helpers::is_empty(body)
179181
&& !visibility::is_abstract(checker, decorator_list)
180182
&& !visibility::is_override(checker, decorator_list)
183+
&& !visibility::is_overload(checker, decorator_list)
181184
{
182185
method(
183186
&Argumentable::ClassMethod,
@@ -202,6 +205,7 @@ pub fn unused_arguments(
202205
&& !helpers::is_empty(body)
203206
&& !visibility::is_abstract(checker, decorator_list)
204207
&& !visibility::is_override(checker, decorator_list)
208+
&& !visibility::is_overload(checker, decorator_list)
205209
{
206210
function(
207211
&Argumentable::StaticMethod,

src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG001_ARG.py.snap

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,73 +5,73 @@ expression: checks
55
- kind:
66
UnusedFunctionArgument: self
77
location:
8-
row: 8
8+
row: 9
99
column: 6
1010
end_location:
11-
row: 8
11+
row: 9
1212
column: 10
1313
fix: ~
1414
- kind:
1515
UnusedFunctionArgument: x
1616
location:
17-
row: 8
17+
row: 9
1818
column: 12
1919
end_location:
20-
row: 8
20+
row: 9
2121
column: 13
2222
fix: ~
2323
- kind:
2424
UnusedFunctionArgument: cls
2525
location:
26-
row: 12
26+
row: 13
2727
column: 6
2828
end_location:
29-
row: 12
29+
row: 13
3030
column: 9
3131
fix: ~
3232
- kind:
3333
UnusedFunctionArgument: x
3434
location:
35-
row: 12
35+
row: 13
3636
column: 11
3737
end_location:
38-
row: 12
38+
row: 13
3939
column: 12
4040
fix: ~
4141
- kind:
4242
UnusedFunctionArgument: self
4343
location:
44-
row: 16
44+
row: 17
4545
column: 6
4646
end_location:
47-
row: 16
47+
row: 17
4848
column: 10
4949
fix: ~
5050
- kind:
5151
UnusedFunctionArgument: x
5252
location:
53-
row: 16
53+
row: 17
5454
column: 12
5555
end_location:
56-
row: 16
56+
row: 17
5757
column: 13
5858
fix: ~
5959
- kind:
6060
UnusedFunctionArgument: cls
6161
location:
62-
row: 20
62+
row: 21
6363
column: 6
6464
end_location:
65-
row: 20
65+
row: 21
6666
column: 9
6767
fix: ~
6868
- kind:
6969
UnusedFunctionArgument: x
7070
location:
71-
row: 20
71+
row: 21
7272
column: 11
7373
end_location:
74-
row: 20
74+
row: 21
7575
column: 12
7676
fix: ~
7777

src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG002_ARG.py.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ expression: checks
55
- kind:
66
UnusedMethodArgument: x
77
location:
8-
row: 34
8+
row: 35
99
column: 16
1010
end_location:
11-
row: 34
11+
row: 35
1212
column: 17
1313
fix: ~
1414
- kind:
1515
UnusedMethodArgument: x
1616
location:
17-
row: 37
17+
row: 38
1818
column: 19
1919
end_location:
20-
row: 37
20+
row: 38
2121
column: 20
2222
fix: ~
2323
- kind:
2424
UnusedMethodArgument: x
2525
location:
26-
row: 40
26+
row: 41
2727
column: 15
2828
end_location:
29-
row: 40
29+
row: 41
3030
column: 16
3131
fix: ~
3232

src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG003_ARG.py.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ expression: checks
55
- kind:
66
UnusedClassMethodArgument: x
77
location:
8-
row: 44
8+
row: 45
99
column: 15
1010
end_location:
11-
row: 44
11+
row: 45
1212
column: 16
1313
fix: ~
1414

src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG004_ARG.py.snap

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,28 @@ expression: checks
55
- kind:
66
UnusedStaticMethodArgument: cls
77
location:
8-
row: 48
8+
row: 49
99
column: 10
1010
end_location:
11-
row: 48
11+
row: 49
1212
column: 13
1313
fix: ~
1414
- kind:
1515
UnusedStaticMethodArgument: x
1616
location:
17-
row: 48
17+
row: 49
1818
column: 15
1919
end_location:
20-
row: 48
20+
row: 49
2121
column: 16
2222
fix: ~
2323
- kind:
2424
UnusedStaticMethodArgument: x
2525
location:
26-
row: 52
26+
row: 53
2727
column: 10
2828
end_location:
29-
row: 52
29+
row: 53
3030
column: 11
3131
fix: ~
3232

src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG005_ARG.py.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ expression: checks
55
- kind:
66
UnusedLambdaArgument: x
77
location:
8-
row: 27
8+
row: 28
99
column: 7
1010
end_location:
11-
row: 27
11+
row: 28
1212
column: 8
1313
fix: ~
1414

0 commit comments

Comments
 (0)