question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

B027 and typing.overload

See original GitHub issue

Consider 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:closed
  • Created 10 months ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jakkdlcommented, Nov 14, 2022

yep!

1reaction
jakkdlcommented, Nov 14, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found