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

Function overloading example does not typecheck #4565

Closed
tyrion opened this Issue Feb 12, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@tyrion
Contributor

tyrion commented Feb 12, 2018

The second code example given on the function overloading documentation gives the error (referred to the last definition of __getitem__): Signature of __getitem__ incompatible with supertype Sequence.

The whole snippet is:

from typing import overload, Sequence, TypeVar, Union
T = TypeVar('T')

class MyList(Sequence[T]):
    @overload
    def __getitem__(self, index: int) -> T:
        pass  # Don't put code here

    @overload
    def __getitem__(self, index: slice) -> Sequence[T]:
        pass  # Don't put code here

    def __getitem__(self, index: Union[int, slice]) -> Union[T, Sequence[T]]:
        raise NotImplementedError
@ilevkivskyi

This comment has been minimized.

Collaborator

ilevkivskyi commented Feb 13, 2018

I think this is because mypy checks the implementation signature against base class (while it shouldn't). If I remove the implementation annotation the error goes away.

Michael0x2a added a commit to Michael0x2a/mypy that referenced this issue Mar 28, 2018

Removes incorrect override check on overloaded methods
This commit fixes python#4565

Currently, when we override a method and annotate the implementation,
mypy appears to run check the legality of the override twice: once for
the overloads, and once for the implementation.

This second check is unnecessary and causes a spurious error.

Michael0x2a added a commit to Michael0x2a/mypy that referenced this issue Mar 28, 2018

Removes incorrect override check on overloaded methods
This commit fixes python#4565

Currently, when we override a method and annotate the implementation,
mypy appears to check the legality of the override twice: once for
the overloads, and once for the implementation.

This second check is unnecessary and causes a spurious error.

ilevkivskyi added a commit that referenced this issue Mar 28, 2018

Removes incorrect override check on overloaded methods (#4810)
This commit fixes #4565

Currently, when we override a method and annotate the implementation,
mypy appears to check the legality of the override twice: once for
the overloads, and once for the implementation.

This second check is unnecessary and causes a spurious error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment