From bc9664231e5ea555bbcfa6c8affab5627be608d4 Mon Sep 17 00:00:00 2001 From: James Lamb Date: Mon, 31 Oct 2022 03:37:02 +0000 Subject: [PATCH] fix typo in unused comparison (B015) message (#307) --- README.rst | 4 ++++ bugbear.py | 7 ++----- tests/b027.py | 13 ++++++++++++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index d2accaf..15ced9a 100644 --- a/README.rst +++ b/README.rst @@ -297,6 +297,10 @@ MIT Change Log ---------- +Future +~~~~~~~~~ +* B027: ignore @overload when typing is import with other names + 22.10.27 ~~~~~~~~~ diff --git a/bugbear.py b/bugbear.py index f02e91a..db4e0c0 100644 --- a/bugbear.py +++ b/bugbear.py @@ -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: @@ -1239,7 +1236,7 @@ def visit_Lambda(self, node): } B015 = Error( message=( - "B015 Result of comparison is not used. This line doesn't do" + "B015 Result of comparison is not used. This line doesn't do " "anything. Did you intend to prepend it with assert?" ) ) diff --git a/tests/b027.py b/tests/b027.py index eb09d99..ef8e9a2 100644 --- a/tests/b027.py +++ b/tests/b027.py @@ -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 @@ -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]): ...