@@ -71,3 +71,27 @@ Ts1 = TypeVarTuple("Ts1", default=2) # E: TypeVarTuple "default" must be a type
7171Ts2 = TypeVarTuple("Ts2", default=int) # E: The default argument to TypeVarTuple must be an Unpacked tuple
7272Ts3 = TypeVarTuple("Ts3", default=Tuple[int]) # E: The default argument to TypeVarTuple must be an Unpacked tuple
7373[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+ P1 = ParamSpec("P1", default=(int, str))
81+ Ts1 = TypeVarTuple("Ts1", default=Unpack[Tuple[int, str]])
82+
83+ def callback1(x: str) -> None: ...
84+
85+ def func1(x: Union[int, T1]) -> List[T1]: ...
86+ reveal_type(func1(2)) # N: Revealed type is "builtins.list[builtins.str]"
87+ reveal_type(func1(2.1)) # N: Revealed type is "builtins.list[builtins.float]"
88+
89+ def func2(x: Union[int, Callable[P1, None]]) -> Callable[P1, None]: ...
90+
91+ reveal_type(func2(callback1)) # N: Revealed type is "def (x: builtins.str)"
92+ reveal_type(func2(2)) # N: Revealed type is "def (builtins.int, builtins.str)"
93+
94+ def func3(x: Union[int, Callable[[Unpack[Ts1]], None]]) -> Tuple[Unpack[Ts1]]: ...
95+ # reveal_type(func3(callback1)) # Revealed type is "builtins.tuple[str]" # TODO
96+ # reveal_type(func3(2)) # Revealed type is "builtins.tuple[builtins.int, builtins.str]" # TODO
97+ [builtins fixtures/tuple.pyi]
0 commit comments