pyflakes: F811 (redefinition of unused variable) incorrectly triggered with @overload decorator
PEP 484 introduced the @overload decorator for type annotations.
[…] a series of
@overload-decorated definitions must be followed by exactly one non-@overload-decorated definition (for the same function/method). The@overload-decorated definitions are for the benefit of the type checker only, since they will be overwritten by the non-@overload-decorated definition, while the latter is used at runtime but should be ignored by a type checker.
The following should pass PyFlakes without errors, but currently triggers F811 errors:
from typing import overload
@overload
def utf8(value: None) -> None:
pass
@overload
def utf8(value: bytes) -> bytes:
pass
@overload
def utf8(value: str) -> bytes:
pass
def utf8(value):
pass # actual implementation
test.py:9:1: F811 redefinition of unused 'utf8' from line 4
test.py:14:1: F811 redefinition of unused 'utf8' from line 9
test.py:19:1: F811 redefinition of unused 'utf8' from line 14
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 20
- Comments: 15 (8 by maintainers)
that’s not possible to detect statically – I’d suggest not doing that (I don’t think mypy can detect that either)
I’d suggest explicitly using the overload decorator
yea works on master, thanks!
Hi, it’s good to see https://github.com/PyCQA/pyflakes/pull/371 solved this partially, but
overloads on classes is still incorrectly triggeredI’m now working around this by using full
typing.overloadname<strike>Added this to
</strike> We ended up adding `# noqa: F811` comments..pydocstylefacing the same issue. do you have a workaround?