@@ -71,3 +71,38 @@ Ts1 = TypeVarTuple("Ts1", default=2) # E: TypeVarTuple "default" must be a type
71
71
Ts2 = TypeVarTuple("Ts2", default=int) # E: The default argument to TypeVarTuple must be an Unpacked tuple
72
72
Ts3 = TypeVarTuple("Ts3", default=Tuple[int]) # E: The default argument to TypeVarTuple must be an Unpacked tuple
73
73
[builtins fixtures/tuple.pyi]
74
+
75
+ [case testTypeVarDefaultsFunctions]
76
+ from typing import TypeVar, ParamSpec, List, Union, Callable, Tuple
77
+ from typing_extensions import TypeVarTuple, Unpack
78
+
79
+ T1 = TypeVar("T1", default=str)
80
+ T2 = TypeVar("T2", bound=str, default=str)
81
+ T3 = TypeVar("T3", bytes, str, default=str)
82
+ P1 = ParamSpec("P1", default=(int, str))
83
+ Ts1 = TypeVarTuple("Ts1", default=Unpack[Tuple[int, str]])
84
+
85
+ def callback1(x: str) -> None: ...
86
+
87
+ def func_a1(x: Union[int, T1]) -> T1: ...
88
+ reveal_type(func_a1(2)) # N: Revealed type is "builtins.str"
89
+ reveal_type(func_a1(2.1)) # N: Revealed type is "builtins.float"
90
+
91
+ def func_a2(x: Union[int, T1]) -> List[T1]: ...
92
+ reveal_type(func_a2(2)) # N: Revealed type is "builtins.list[builtins.str]"
93
+ reveal_type(func_a2(2.1)) # N: Revealed type is "builtins.list[builtins.float]"
94
+
95
+ def func_a3(x: Union[int, T2]) -> T2: ...
96
+ reveal_type(func_a3(2)) # N: Revealed type is "builtins.str"
97
+
98
+ def func_a4(x: Union[int, T3]) -> T3: ...
99
+ reveal_type(func_a4(2)) # N: Revealed type is "builtins.str"
100
+
101
+ def func_b1(x: Union[int, Callable[P1, None]]) -> Callable[P1, None]: ...
102
+ reveal_type(func_b1(callback1)) # N: Revealed type is "def (x: builtins.str)"
103
+ reveal_type(func_b1(2)) # N: Revealed type is "def (builtins.int, builtins.str)"
104
+
105
+ def func_c1(x: Union[int, Callable[[Unpack[Ts1]], None]]) -> Tuple[Unpack[Ts1]]: ...
106
+ # reveal_type(func_c1(callback1)) # Revealed type is "builtins.tuple[str]" # TODO
107
+ # reveal_type(func_c1(2)) # Revealed type is "builtins.tuple[builtins.int, builtins.str]" # TODO
108
+ [builtins fixtures/tuple.pyi]
0 commit comments