Skip to content

Commit f2ae738

Browse files
committed
Add an option to include functions decorated with @overload.
Fixes nhoad#10.
1 parent fea37ea commit f2ae738

3 files changed

Lines changed: 39 additions & 1 deletion

File tree

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ This package adds the following warnings:
99

1010
Configuration options also exist:
1111
- `unused-arguments-ignore-abstract-functions` - don't show warnings for abstract functions.
12+
- `unused-arguments-ignore-overload-functions` - don't show warnings for overload functions.
1213
- `unused-arguments-ignore-stub-functions` - don't show warnings for empty functions.
1314
- `unused-arguments-ignore-variadic-names` - don't show warnings for unused *args and **kwargs.
1415
- `unused-arguments-ignore-lambdas` - don't show warnings for all lambdas.
@@ -23,6 +24,9 @@ Configuration options also exist:
2324

2425
## Changelog
2526

27+
0.0.11
28+
- Added a new option for ignoring functions decorated with overload.
29+
2630
0.0.10
2731
- Added new options for ignoring lambdas and nested functions. Thanks to João Eiras for contributing these!
2832

flake8_unused_arguments.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ class Plugin:
1515
version = "0.0.10"
1616

1717
ignore_abstract = False
18+
ignore_overload = False
1819
ignore_stubs = False
1920
ignore_variadic_names = False
2021
ignore_lambdas = False
@@ -35,6 +36,15 @@ def add_options(cls, option_manager: flake8.options.manager.OptionManager) -> No
3536
help="If provided, then unused arguments for functions decorated with abstractmethod will be ignored.",
3637
)
3738

39+
option_manager.add_option(
40+
"--unused-arguments-ignore-overload-functions",
41+
action="store_true",
42+
parse_from_config=True,
43+
default=cls.ignore_overload,
44+
dest="unused_arguments_ignore_overload_functions",
45+
help="If provided, then unused arguments for functions decorated with overload will be ignored.",
46+
)
47+
3848
option_manager.add_option(
3949
"--unused-arguments-ignore-stub-functions",
4050
action="store_true",
@@ -89,6 +99,7 @@ def add_options(cls, option_manager: flake8.options.manager.OptionManager) -> No
8999
@classmethod
90100
def parse_options(cls, options: optparse.Values) -> None:
91101
cls.ignore_abstract = options.unused_arguments_ignore_abstract_functions
102+
cls.ignore_overload = options.unused_arguments_ignore_overload_functions
92103
cls.ignore_stubs = options.unused_arguments_ignore_stub_functions
93104
cls.ignore_variadic_names = options.unused_arguments_ignore_variadic_names
94105
cls.ignore_lambdas = options.unused_arguments_ignore_lambdas
@@ -101,7 +112,12 @@ def run(self) -> Iterable[LintResult]:
101112

102113
for function in finder.functions:
103114
decorator_names = set(get_decorator_names(function))
104-
# ignore abtractmethods, it's not a surprise when they're empty
115+
116+
# ignore overload functions, it's not a surprise when they're empty
117+
if self.ignore_overload and "overload" in decorator_names:
118+
continue
119+
120+
# ignore abstractmethods, it's not a surprise when they're empty
105121
if self.ignore_abstract and "abstractmethod" in decorator_names:
106122
continue
107123

test_unused_arguments.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,24 @@ def foo(a):
178178
),
179179
(
180180
"""
181+
@overload
182+
def foo(a):
183+
pass
184+
""",
185+
{"ignore_overload": False},
186+
[(3, 8, "U100 Unused argument 'a'", "unused argument")],
187+
),
188+
(
189+
"""
190+
@overload
191+
def foo(a):
192+
pass
193+
""",
194+
{"ignore_overload": True},
195+
[],
196+
),
197+
(
198+
"""
181199
def foo(a):
182200
pass
183201
""",

0 commit comments

Comments
 (0)