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

F811 (redefinition of unused variable) incorrectly triggered with @overload decorator #434

Closed
smoehrle opened this issue Feb 22, 2019 · 5 comments · Fixed by #435
Closed

Comments

@smoehrle
Copy link

smoehrle commented Feb 22, 2019

This bug was fixed for functions in #320. It still occurs if the function is inside a class and/or has multiple decorators (e.g. @staticmethod, @classmethod):

from typing import overload


class test:
    @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:5: F811 redefinition of unused 'utf8' from line 5
test.py:13:5: F811 redefinition of unused 'utf8' from line 9
test.py:17:5: F811 redefinition of unused 'utf8' from line 13
from typing import overload


def do_nothing(func):
    return func


@overload
@do_nothing
def utf8(value: None) -> None:
    pass


@overload
@do_nothing
def utf8(value: bytes) -> bytes:
    pass


@overload
@do_nothing
def utf8(value: str) -> bytes:
    pass


def utf8(value):
    pass  # actual implementation
test.py:14:1: F811 redefinition of unused 'utf8' from line 8
test.py:20:1: F811 redefinition of unused 'utf8' from line 14
test.py:26:1: F811 redefinition of unused 'utf8' from line 20
@asottile
Copy link
Member

can confirm, thanks for the report -- one of these is easy to fix -- trying to figure out the other one right now 👍

@asottile
Copy link
Member

@smoehrle want to try out the branch in #435?

@smoehrle
Copy link
Author

@asottile Can confirm the fix :) Thanks for the fast response

@fr0der1c
Copy link

I am wondering... Should the @overhead decorator be put below or above other decorators?

PyCharm complains if I put the @overhead decorator above other decorators.
image

@asottile
Copy link
Member

I think it ends up not mattering, since you won't ever be calling the @overload decorated methods, but the definition below them.

probably a bug that pycharm reports that

https://github.com/python/cpython/blob/4173772031747a9b249be4100b4aa9eda805ea23/Lib/typing.py#L1049-L1084

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants