Skip to content

Commit 8b47c00

Browse files
committed
WIP
1 parent 8196863 commit 8b47c00

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

test-data/unit/check-typevar-defaults.test

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def func_error_alias2(
151151
[builtins fixtures/dict.pyi]
152152

153153
[case testTypeVarDefaultsFunctions]
154-
from typing import TypeVar, ParamSpec, List, Union, Callable, Tuple
154+
from typing import TypeVar, ParamSpec, List, Union, Callable, Tuple, overload
155155
from typing_extensions import TypeVarTuple, Unpack
156156

157157
T1 = TypeVar("T1", default=str)
@@ -183,6 +183,14 @@ reveal_type(func_b1(2)) # N: Revealed type is "def (builtins.int, builtins.str)
183183
def func_c1(x: Union[int, Callable[[Unpack[Ts1]], None]]) -> Tuple[Unpack[Ts1]]: ...
184184
# reveal_type(func_c1(callback1)) # Revealed type is "builtins.tuple[str]" # TODO
185185
# reveal_type(func_c1(2)) # Revealed type is "builtins.tuple[builtins.int, builtins.str]" # TODO
186+
187+
@overload
188+
def func_d1(x: int) -> int: ...
189+
@overload
190+
def func_d1(x: Union[float, T1]) -> T1: ...
191+
def func_d1(x): ...
192+
reveal_type(func_d1(2)) # N: Revealed type is "builtins.int"
193+
reveal_type(func_d1(2.1)) # N: Revealed type is "builtins.str"
186194
[builtins fixtures/tuple.pyi]
187195

188196
[case testTypeVarDefaultsClass1]
@@ -417,6 +425,26 @@ def func_c4(
417425
reveal_type(m) # N: Revealed type is "__main__.ClassC4[builtins.int, builtins.float]"
418426
[builtins fixtures/tuple.pyi]
419427

428+
[case testTypeVarDefaultsClass4]
429+
# flags: --disallow-any-generics
430+
from typing import Dict, Generic, List, TypeVar, Tuple
431+
432+
T1 = TypeVar("T1", default=str)
433+
T2 = TypeVar("T2", default=T1)
434+
T3 = TypeVar("T3", default=Tuple[T2])
435+
T4 = TypeVar("T4", default=Tuple[T1, T2])
436+
T5 = TypeVar("T5", default="T5")
437+
438+
class ClassD1(Generic[T1, T2]): ...
439+
440+
# def func_d1(c: ClassD1[int]) -> None:
441+
# a = ClassD1[int]()
442+
# reveal_type(a) # Revealed type is "__main__.ClassD1[builtins.int, builtins.int]"
443+
# b = ClassD1()
444+
# reveal_type(b) # Revealed type is "__main__.ClassD1[builtins.str, builtins.str]"
445+
# reveal_type(c)
446+
[builtins fixtures/tuple.pyi]
447+
420448
[case testTypeVarDefaultsClassRecursive1]
421449
# flags: --disallow-any-generics
422450
from typing import Generic, TypeVar, List

0 commit comments

Comments
 (0)