@@ -83,7 +83,7 @@ T4 = TypeVar("T4", int, str, default=Union[int, str]) # E: TypeVar default must
83
83
T5 = TypeVar("T5", float, str, default=int) # E: TypeVar default must be one of the constraint types
84
84
85
85
[case testTypeVarDefaultsFunctions]
86
- from typing import TypeVar, ParamSpec, List, Union, Callable, Tuple
86
+ from typing import TypeVar, ParamSpec, List, Union, Callable, Tuple, overload
87
87
from typing_extensions import TypeVarTuple, Unpack
88
88
89
89
T1 = TypeVar("T1", default=str)
@@ -115,6 +115,14 @@ reveal_type(func_b1(2)) # N: Revealed type is "def (builtins.int, builtins.str)
115
115
def func_c1(x: Union[int, Callable[[Unpack[Ts1]], None]]) -> Tuple[Unpack[Ts1]]: ...
116
116
# reveal_type(func_c1(callback1)) # Revealed type is "builtins.tuple[str]" # TODO
117
117
# 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"
118
126
[builtins fixtures/tuple.pyi]
119
127
120
128
[case testTypeVarDefaultsClass1]
@@ -349,6 +357,26 @@ def func_c4(
349
357
reveal_type(m) # N: Revealed type is "__main__.ClassC4[builtins.int, builtins.float]"
350
358
[builtins fixtures/tuple.pyi]
351
359
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
+
352
380
[case testTypeVarDefaultsTypeAlias1]
353
381
# flags: --disallow-any-generics
354
382
from typing import Any, Dict, List, Tuple, TypeVar, Union
0 commit comments