You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Overload validation does not properly handle implied subtype relationships (e.g. int and float) #10143
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: strictfromtypingimportLiteral, Union, overloadclassParent: ...
classChild(Parent): ...
# Test 1: Literal subtype@overloaddeffoo1(x: Literal[3]) ->int: ...
@overloaddeffoo1(x: int) ->str: ...
# Test 2: Subclass subtype@overloaddeffoo2(x: Child) ->str: ...
@overloaddeffoo2(x: Parent) ->int: ...
# Test 3: Implicit subtype@overloaddeffoo3(x: int) ->str: ... # Mypy does not report error here@overloaddeffoo3(x: float) ->int: ...
# Test 4: Union subtype@overloaddeffoo4(x: int) ->str: ...
@overloaddeffoo4(x: Union[int, str]) ->int: ...
Activity
JukkaL commentedon Mar 5, 2021
Yeah, we should treat
intas a subtype offloathere.