Skip to content

Commit 356f0dc

Browse files
authored
B027 now ignores @[anything].overload to reduce false positives. (#309)
1 parent 9652dbd commit 356f0dc

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.rst

+4
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,10 @@ MIT
297297
Change Log
298298
----------
299299

300+
Future
301+
~~~~~~~~~
302+
* B027: ignore @overload when typing is import with other names
303+
300304
22.10.27
301305
~~~~~~~~~
302306

bugbear.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -671,10 +671,7 @@ def is_abstract_decorator(expr):
671671

672672
def is_overload(expr):
673673
return (isinstance(expr, ast.Name) and expr.id == "overload") or (
674-
isinstance(expr, ast.Attribute)
675-
and isinstance(expr.value, ast.Name)
676-
and expr.value.id == "typing"
677-
and expr.attr == "overload"
674+
isinstance(expr, ast.Attribute) and expr.attr == "overload"
678675
)
679676

680677
def empty_body(body) -> bool:

tests/b027.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ def empty_2(self): # safe
6060

6161

6262
# ignore @overload, fixes issue #304
63+
# ignore overload with other imports, fixes #308
6364
import typing
65+
import typing as t
66+
import typing as anything
6467
from typing import Union, overload
6568

6669

@@ -73,6 +76,14 @@ def empty_1(self, foo: str):
7376
def empty_1(self, foo: int):
7477
...
7578

79+
@t.overload
80+
def empty_1(self, foo: list):
81+
...
82+
83+
@anything.overload
84+
def empty_1(self, foo: float):
85+
...
86+
7687
@abstractmethod
77-
def empty_1(self, foo: Union[str, int]):
88+
def empty_1(self, foo: Union[str, int, list, float]):
7889
...

0 commit comments

Comments
 (0)