Skip to content

Overlapping overload detection fails when signature contains TypeVar #10157

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

Open
erictraut opened this issue Mar 2, 2021 · 1 comment
Open
Labels
bug mypy got something wrong topic-overloads

Comments

@erictraut
Copy link

Mypy detects and reports overlapping function overloads that differ in return type.

In the example below, it correctly reports that the second overload of func1 overlaps the first overload. However, when the concrete type str is replaced by a generic type _T, it fails to report the error.

@overload
def func1(
    a: str,
    b: Literal[False] = ...,
) -> List[str]: ...
@overload
def func1(
    a: str,
    b: bool = ...,
) -> List[Union[str, int]]: ...

_T = TypeVar("_T")
@overload
def func2(
    a: _T,
    b: Literal[False] = ...,
) -> List[_T]: ...
@overload
def func2(
    a: _T,
    b: bool = ...,
) -> List[Union[_T, int]]: ...
@erictraut erictraut added the bug mypy got something wrong label Mar 2, 2021
@JukkaL
Copy link
Collaborator

JukkaL commented Mar 5, 2021

This is a false negative. Both overloaded functions are overlapping.

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-overloads
Projects
None yet
Development

No branches or pull requests

2 participants