Open
Description
I'm working to make pyright's overload validation work consistently with mypy's.
Mypy's overload validation behavior is spec'ed here: python/typing#253 (comment)
As part of this validation, mypy reports errors when there is overlap between two overloads that return different return types. The following test case shows four such examples. Mypy properly reports the error in three of the four cases, but it misses the case where there is an implied subtype relationship, as between int
and float
.
# pyright: strict
from typing import Literal, Union, overload
class Parent: ...
class Child(Parent): ...
# Test 1: Literal subtype
@overload
def foo1(x: Literal[3]) -> int: ...
@overload
def foo1(x: int) -> str: ...
# Test 2: Subclass subtype
@overload
def foo2(x: Child) -> str: ...
@overload
def foo2(x: Parent) -> int: ...
# Test 3: Implicit subtype
@overload
def foo3(x: int) -> str: ... # Mypy does not report error here
@overload
def foo3(x: float) -> int: ...
# Test 4: Union subtype
@overload
def foo4(x: int) -> str: ...
@overload
def foo4(x: Union[int, str]) -> int: ...