Skip to content

Commit

Permalink
B027 now ignores @[anything].overload to reduce false positives. (#309)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Nov 7, 2022
1 parent 9652dbd commit 356f0dc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.rst
Expand Up @@ -297,6 +297,10 @@ MIT
Change Log
----------

Future
~~~~~~~~~
* B027: ignore @overload when typing is import with other names

22.10.27
~~~~~~~~~

Expand Down
5 changes: 1 addition & 4 deletions bugbear.py
Expand Up @@ -671,10 +671,7 @@ def is_abstract_decorator(expr):

def is_overload(expr):
return (isinstance(expr, ast.Name) and expr.id == "overload") or (
isinstance(expr, ast.Attribute)
and isinstance(expr.value, ast.Name)
and expr.value.id == "typing"
and expr.attr == "overload"
isinstance(expr, ast.Attribute) and expr.attr == "overload"
)

def empty_body(body) -> bool:
Expand Down
13 changes: 12 additions & 1 deletion tests/b027.py
Expand Up @@ -60,7 +60,10 @@ def empty_2(self): # safe


# ignore @overload, fixes issue #304
# ignore overload with other imports, fixes #308
import typing
import typing as t
import typing as anything
from typing import Union, overload


Expand All @@ -73,6 +76,14 @@ def empty_1(self, foo: str):
def empty_1(self, foo: int):
...

@t.overload
def empty_1(self, foo: list):
...

@anything.overload
def empty_1(self, foo: float):
...

@abstractmethod
def empty_1(self, foo: Union[str, int]):
def empty_1(self, foo: Union[str, int, list, float]):
...

0 comments on commit 356f0dc

Please sign in to comment.