Skip to content

Overlapping overload detection fails when signature contains TypeVar #10157

@erictraut

Description

@erictraut

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]]: ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions