Skip to content

Non-applicable overloads should not be requested in subclasses #13591

Closed
@vnmabus

Description

@vnmabus

In the following case, Mypy complains about an invalid signature for the foo method in the implementation class, as it was missing an overload.

However, the missing overload is not applicable to that subclass and should not be requested.

from __future__ import annotations

from typing import overload, Generic, TypeVar

T = TypeVar("T")

class Interface(Generic[T]):
    @overload
    def foo(self: Interface[None]) -> int:
        ...

    @overload
    def foo(self, a: T) -> int:
        ...

    def foo(self, a: T | None = None) -> str | int:
        return 1


class Implementation(Interface[int]):
    
    def foo(self, a: int) -> int:
        return 2

Originally posted by @vnmabus in #13106 (comment)

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions