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

Incorrect incompatible override report with self type + overload #14002

Closed
JelleZijlstra opened this issue Nov 4, 2022 · 0 comments · Fixed by #14017
Closed

Incorrect incompatible override report with self type + overload #14002

JelleZijlstra opened this issue Nov 4, 2022 · 0 comments · Fixed by #14017
Labels
bug mypy got something wrong topic-inheritance Inheritance and incompatible overrides topic-overloads

Comments

@JelleZijlstra
Copy link
Member

Given this code:

from typing import overload, TypeVar, Generic

T = TypeVar("T", str, int)

class A(Generic[T]):
    @overload
    def f(self: A[int]) -> int: ...
    @overload
    def f(self: A[str]) -> str: ...
    def f(self): ...
    
class B(A[int]):
    def f(self) -> int: ...

https://mypy-play.net/?mypy=latest&python=3.10&gist=736b946030f3c52e14c712ce7e95464c

mypy 0.981 reports main.py:13: error: Signature of "f" incompatible with supertype "A".

This is incorrect: B is an A[int], so it doesn't matter that it doesn't implement the second overload.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-inheritance Inheritance and incompatible overrides topic-overloads
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant