B027 and typing.overload
See original GitHub issueConsider the following:
class Foo(ABC):
@t.overload
def bar(self, arg: t.Literal[False]) -> t.Literal[False]:
...
@t.overload
def bar(self, arg: t.Literal[True]) -> t.Literal[True]:
...
def bar(self, arg: bool) -> bool:
return arg
@abstractmethod
def abstract_method(self) -> None:
...
The overloads of bar are considered as “real” methods and B027 warning is emitted:
B027 bar is an empty method in an abstract base class, but has no abstract decorator. Consider adding @abstractmethod.
B027 bar is an empty method in an abstract base class, but has no abstract decorator. Consider adding @abstractmethod.
Is it worth not emitting the warning when typing.overload is used or is it a case that should be supressed manually with # noqa?
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
B027 now ignores @[anything].overload to reduce false ...
Fixes #304 it also ignores @a.b.c.d.overload in case somebody is writing a custom overload or importing typing in some very weird way -...
Read more >Making sense of typing.overload - Medium
overload. Suppose we have a function which take a boolean argument inplace and that its return type depends on the value of inplace...
Read more >python typing: @overload (intermediate) anthony explains #163
today I talk about the @ overload decorator for typing and how it can be used to signal typed-dispatch to a type checker!...
Read more >flake8-bugbear - PyPI
B027 : Empty method in abstract base class, but has no abstract decorator. ... (#314). B027: ignore @overload when typing is imported with...
Read more >Python: How to write typing.overload decorator for bool ...
Install the typing-extensions module which contains official backports of various typing constructs. Then, do: from typing import overload, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

yep!
Typecheckers evaluate imports, but AST checkers like flake8 usually don’t try and just looks at identifiers hoping/assuming they’re well-named. (afaik)
Anyway, fixed with #309 - forgot to mention this issue in it.