Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

B027 now ignores @[anything].overload to reduce false positives. #309

Merged
merged 1 commit into from Nov 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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]):
...