@@ -83,7 +83,7 @@ T4 = TypeVar("T4", int, str, default=Union[int, str]) # E: TypeVar default must
8383T5 = TypeVar("T5", float, str, default=int) # E: TypeVar default must be one of the constraint types
8484
8585[case testTypeVarDefaultsFunctions]
86- from typing import TypeVar, ParamSpec, List, Union, Callable, Tuple
86+ from typing import TypeVar, ParamSpec, List, Union, Callable, Tuple, overload
8787from typing_extensions import TypeVarTuple, Unpack
8888
8989T1 = TypeVar("T1", default=str)
@@ -115,6 +115,14 @@ reveal_type(func_b1(2)) # N: Revealed type is "def (builtins.int, builtins.str)
115115def func_c1(x: Union[int, Callable[[Unpack[Ts1]], None]]) -> Tuple[Unpack[Ts1]]: ...
116116# reveal_type(func_c1(callback1)) # Revealed type is "builtins.tuple[str]" # TODO
117117# reveal_type(func_c1(2)) # Revealed type is "builtins.tuple[builtins.int, builtins.str]" # TODO
118+
119+ @overload
120+ def func_d1(x: int) -> int: ...
121+ @overload
122+ def func_d1(x: Union[float, T1]) -> T1: ...
123+ def func_d1(x): ...
124+ reveal_type(func_d1(2)) # N: Revealed type is "builtins.int"
125+ reveal_type(func_d1(2.1)) # N: Revealed type is "builtins.str"
118126[builtins fixtures/tuple.pyi]
119127
120128[case testTypeVarDefaultsClass1]
@@ -349,6 +357,26 @@ def func_c4(
349357 reveal_type(m) # N: Revealed type is "__main__.ClassC4[builtins.int, builtins.float]"
350358[builtins fixtures/tuple.pyi]
351359
360+ [case testTypeVarDefaultsClass4]
361+ # flags: --disallow-any-generics
362+ from typing import Dict, Generic, List, TypeVar, Tuple
363+
364+ T1 = TypeVar("T1", default=str)
365+ T2 = TypeVar("T2", default=T1)
366+ T3 = TypeVar("T3", default=Tuple[T2])
367+ T4 = TypeVar("T4", default=Tuple[T1, T2])
368+ T5 = TypeVar("T5", default="T5")
369+
370+ class ClassD1(Generic[T1, T2]): ...
371+
372+ # def func_d1(c: ClassD1[int]) -> None:
373+ # a = ClassD1[int]()
374+ # reveal_type(a) # Revealed type is "__main__.ClassD1[builtins.int, builtins.int]"
375+ # b = ClassD1()
376+ # reveal_type(b) # Revealed type is "__main__.ClassD1[builtins.str, builtins.str]"
377+ # reveal_type(c)
378+ [builtins fixtures/tuple.pyi]
379+
352380[case testTypeVarDefaultsTypeAlias1]
353381# flags: --disallow-any-generics
354382from typing import Any, Dict, List, Tuple, TypeVar, Union
0 commit comments