Skip to content

Commit

Permalink
Ignore unused arguments for @overload stubs (#1373)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Dec 25, 2022
1 parent dca3fcd commit 9bb470c
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 32 deletions.
18 changes: 18 additions & 0 deletions resources/test/fixtures/flake8_unused_arguments/ARG.py
@@ -1,4 +1,5 @@
from abc import abstractmethod
from typing import overload
from typing_extensions import override


Expand Down Expand Up @@ -135,3 +136,20 @@ def f(cls, x):
@override
def f(x):
print("Hello, world!")


###
# Unused arguments attached to overloads (OK).
###
@overload
def f(a: str, b: str) -> str:
...


@overload
def f(a: int, b: int) -> str:
...


def f(a, b):
return f"{a}{b}"
4 changes: 4 additions & 0 deletions src/flake8_unused_arguments/plugins.rs
Expand Up @@ -130,6 +130,7 @@ pub fn unused_arguments(
.settings
.enabled
.contains(Argumentable::Function.check_code())
&& !visibility::is_overload(checker, decorator_list)
{
function(
&Argumentable::Function,
Expand All @@ -154,6 +155,7 @@ pub fn unused_arguments(
&& !helpers::is_empty(body)
&& !visibility::is_abstract(checker, decorator_list)
&& !visibility::is_override(checker, decorator_list)
&& !visibility::is_overload(checker, decorator_list)
{
method(
&Argumentable::Method,
Expand All @@ -178,6 +180,7 @@ pub fn unused_arguments(
&& !helpers::is_empty(body)
&& !visibility::is_abstract(checker, decorator_list)
&& !visibility::is_override(checker, decorator_list)
&& !visibility::is_overload(checker, decorator_list)
{
method(
&Argumentable::ClassMethod,
Expand All @@ -202,6 +205,7 @@ pub fn unused_arguments(
&& !helpers::is_empty(body)
&& !visibility::is_abstract(checker, decorator_list)
&& !visibility::is_override(checker, decorator_list)
&& !visibility::is_overload(checker, decorator_list)
{
function(
&Argumentable::StaticMethod,
Expand Down
Expand Up @@ -5,73 +5,73 @@ expression: checks
- kind:
UnusedFunctionArgument: self
location:
row: 8
row: 9
column: 6
end_location:
row: 8
row: 9
column: 10
fix: ~
- kind:
UnusedFunctionArgument: x
location:
row: 8
row: 9
column: 12
end_location:
row: 8
row: 9
column: 13
fix: ~
- kind:
UnusedFunctionArgument: cls
location:
row: 12
row: 13
column: 6
end_location:
row: 12
row: 13
column: 9
fix: ~
- kind:
UnusedFunctionArgument: x
location:
row: 12
row: 13
column: 11
end_location:
row: 12
row: 13
column: 12
fix: ~
- kind:
UnusedFunctionArgument: self
location:
row: 16
row: 17
column: 6
end_location:
row: 16
row: 17
column: 10
fix: ~
- kind:
UnusedFunctionArgument: x
location:
row: 16
row: 17
column: 12
end_location:
row: 16
row: 17
column: 13
fix: ~
- kind:
UnusedFunctionArgument: cls
location:
row: 20
row: 21
column: 6
end_location:
row: 20
row: 21
column: 9
fix: ~
- kind:
UnusedFunctionArgument: x
location:
row: 20
row: 21
column: 11
end_location:
row: 20
row: 21
column: 12
fix: ~

Expand Up @@ -5,28 +5,28 @@ expression: checks
- kind:
UnusedMethodArgument: x
location:
row: 34
row: 35
column: 16
end_location:
row: 34
row: 35
column: 17
fix: ~
- kind:
UnusedMethodArgument: x
location:
row: 37
row: 38
column: 19
end_location:
row: 37
row: 38
column: 20
fix: ~
- kind:
UnusedMethodArgument: x
location:
row: 40
row: 41
column: 15
end_location:
row: 40
row: 41
column: 16
fix: ~

Expand Up @@ -5,10 +5,10 @@ expression: checks
- kind:
UnusedClassMethodArgument: x
location:
row: 44
row: 45
column: 15
end_location:
row: 44
row: 45
column: 16
fix: ~

Expand Up @@ -5,28 +5,28 @@ expression: checks
- kind:
UnusedStaticMethodArgument: cls
location:
row: 48
row: 49
column: 10
end_location:
row: 48
row: 49
column: 13
fix: ~
- kind:
UnusedStaticMethodArgument: x
location:
row: 48
row: 49
column: 15
end_location:
row: 48
row: 49
column: 16
fix: ~
- kind:
UnusedStaticMethodArgument: x
location:
row: 52
row: 53
column: 10
end_location:
row: 52
row: 53
column: 11
fix: ~

Expand Up @@ -5,10 +5,10 @@ expression: checks
- kind:
UnusedLambdaArgument: x
location:
row: 27
row: 28
column: 7
end_location:
row: 27
row: 28
column: 8
fix: ~

0 comments on commit 9bb470c

Please sign in to comment.