From 6ea9f0ad5bde3309fc7c83a9a7f29d3ec66fdc30 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Sun, 25 Dec 2022 17:21:36 -0500 Subject: [PATCH] Ignore unused arguments for @overload stubs --- .../fixtures/flake8_unused_arguments/ARG.py | 18 +++++++++++ src/flake8_unused_arguments/plugins.rs | 4 +++ ...nused_arguments__tests__ARG001_ARG.py.snap | 32 +++++++++---------- ...nused_arguments__tests__ARG002_ARG.py.snap | 12 +++---- ...nused_arguments__tests__ARG003_ARG.py.snap | 4 +-- ...nused_arguments__tests__ARG004_ARG.py.snap | 12 +++---- ...nused_arguments__tests__ARG005_ARG.py.snap | 4 +-- 7 files changed, 54 insertions(+), 32 deletions(-) diff --git a/resources/test/fixtures/flake8_unused_arguments/ARG.py b/resources/test/fixtures/flake8_unused_arguments/ARG.py index 2f167890d45a9..a01838f2d4e19 100644 --- a/resources/test/fixtures/flake8_unused_arguments/ARG.py +++ b/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 @@ -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}" diff --git a/src/flake8_unused_arguments/plugins.rs b/src/flake8_unused_arguments/plugins.rs index cc9797e85a9a3..6f1f385053857 100644 --- a/src/flake8_unused_arguments/plugins.rs +++ b/src/flake8_unused_arguments/plugins.rs @@ -130,6 +130,7 @@ pub fn unused_arguments( .settings .enabled .contains(Argumentable::Function.check_code()) + && !visibility::is_overload(checker, decorator_list) { function( &Argumentable::Function, @@ -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, @@ -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, @@ -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, diff --git a/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG001_ARG.py.snap b/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG001_ARG.py.snap index 33065dd58b24e..eb1ffbca03f04 100644 --- a/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG001_ARG.py.snap +++ b/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG001_ARG.py.snap @@ -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: ~ diff --git a/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG002_ARG.py.snap b/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG002_ARG.py.snap index c0a9ee37b8028..9bc7321f781f7 100644 --- a/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG002_ARG.py.snap +++ b/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG002_ARG.py.snap @@ -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: ~ diff --git a/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG003_ARG.py.snap b/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG003_ARG.py.snap index 71b7743912c8c..da1219718703a 100644 --- a/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG003_ARG.py.snap +++ b/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG003_ARG.py.snap @@ -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: ~ diff --git a/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG004_ARG.py.snap b/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG004_ARG.py.snap index de63f5c54c894..b848ba8ae9adf 100644 --- a/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG004_ARG.py.snap +++ b/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG004_ARG.py.snap @@ -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: ~ diff --git a/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG005_ARG.py.snap b/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG005_ARG.py.snap index 1b97ee045fd55..017dfc64e21ab 100644 --- a/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG005_ARG.py.snap +++ b/src/flake8_unused_arguments/snapshots/ruff__flake8_unused_arguments__tests__ARG005_ARG.py.snap @@ -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: ~