Skip to content

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

Closed

Description

@smoehrle

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

Activity

  1. asottile commented on Feb 22, 2019

    @asottile
    Member

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

  2. asottile commented on Feb 22, 2019

    @asottile
    Member

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

  3. smoehrle commented on Feb 23, 2019

    @smoehrle
    Author

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

  4. fr0der1c commented on Feb 28, 2019

    @fr0der1c

    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

  5. asottile commented on Feb 28, 2019

    @asottile
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions