Skip to content

Incorrect incompatible override report with self type + overload #14002

Closed
@JelleZijlstra

Description

@JelleZijlstra

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions