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
# A broad type before a specific Literal means the Literal can never match.
6913
+
from typing import overload, Literal
6914
+
@overload
6915
+
def f(x: str) -> int: ...
6916
+
@overload
6917
+
def f(x: Literal["a"]) -> str: ... # E: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader
6918
+
def f(x: str) -> object:
6919
+
return x
6920
+
[builtins fixtures/tuple.pyi]
6921
+
6922
+
[case testOverloadLiteralImplErrorsNotSuppressed]
6923
+
# The literal fast path must not suppress implementation-body consistency errors.
6924
+
# Use bytes as the impl return type — incompatible with both int and str.
6925
+
from typing import overload, Literal
6926
+
@overload
6927
+
def f(x: Literal["a"]) -> int: ...
6928
+
@overload
6929
+
def f(x: Literal["b"]) -> str: ...
6930
+
def f(x: str) -> bytes: # E: Overloaded function implementation cannot produce return type of signature 1 # E: Overloaded function implementation cannot produce return type of signature 2
6931
+
return b""
6932
+
[builtins fixtures/tuple.pyi]
6933
+
6934
+
[case testOverloadLiteralUnionDistinctNoError]
6935
+
# Literal unions with disjoint value sets are provably disjoint; no errors.
6936
+
from typing import overload, Literal, Union
6937
+
@overload
6938
+
def f(x: Literal["a", "b"]) -> int: ...
6939
+
@overload
6940
+
def f(x: Literal["c", "d"]) -> str: ...
6941
+
def f(x: str) -> object:
6942
+
return x
6943
+
[builtins fixtures/tuple.pyi]
6944
+
6945
+
[case testOverloadLiteralUnionOverlapErrors]
6946
+
# Literal unions that share a value are NOT disjoint and should be flagged.
6947
+
from typing import overload, Literal
6948
+
@overload
6949
+
def f(x: Literal["a", "b"]) -> int: ... # E: Overloaded function signatures 1 and 2 overlap with incompatible return types
6950
+
@overload
6951
+
def f(x: Literal["b", "c"]) -> str: ...
6952
+
def f(x: str) -> object:
6953
+
return x
6954
+
[builtins fixtures/tuple.pyi]
6955
+
6956
+
[case testOverloadLiteralUnionMixedNoFastPath]
6957
+
# A union with a non-Literal member is not fingerprinted, so the full check runs.
6958
+
from typing import overload, Literal, Union
6959
+
@overload
6960
+
def f(x: Literal["a"]) -> int: ... # E: Overloaded function signatures 1 and 2 overlap with incompatible return types
0 commit comments