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

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

Closed
vnmabus opened this issue Sep 2, 2022 · 2 comments
Closed

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

vnmabus opened this issue Sep 2, 2022 · 2 comments
Labels

Comments

@vnmabus
Copy link

vnmabus commented Sep 2, 2022

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)

@erictraut
Copy link

This appears to have been fixed in mypy 1.2.0.

@AlexWaygood
Copy link
Member

Yeah, I think I remember the PR that fixed it, as well. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants