Skip to content

Commit 33a60cc

Browse files
committed
WIP
1 parent 98d3710 commit 33a60cc

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
@@ -83,7 +83,7 @@ T4 = TypeVar("T4", int, str, default=Union[int, str]) # E: TypeVar default must
8383
T5 = 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
8787
from typing_extensions import TypeVarTuple, Unpack
8888

8989
T1 = TypeVar("T1", default=str)
@@ -115,6 +115,14 @@ reveal_type(func_b1(2)) # N: Revealed type is "def (builtins.int, builtins.str)
115115
def 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]
@@ -334,6 +342,26 @@ def func_c4(
334342
reveal_type(m) # N: Revealed type is "__main__.ClassC4[builtins.int, builtins.float]"
335343
[builtins fixtures/tuple.pyi]
336344

345+
[case testTypeVarDefaultsClass4]
346+
# flags: --disallow-any-generics
347+
from typing import Dict, Generic, List, TypeVar, Tuple
348+
349+
T1 = TypeVar("T1", default=str)
350+
T2 = TypeVar("T2", default=T1)
351+
T3 = TypeVar("T3", default=Tuple[T2])
352+
T4 = TypeVar("T4", default=Tuple[T1, T2])
353+
T5 = TypeVar("T5", default="T5")
354+
355+
class ClassD1(Generic[T1, T2]): ...
356+
357+
# def func_d1(c: ClassD1[int]) -> None:
358+
# a = ClassD1[int]()
359+
# reveal_type(a) # Revealed type is "__main__.ClassD1[builtins.int, builtins.int]"
360+
# b = ClassD1()
361+
# reveal_type(b) # Revealed type is "__main__.ClassD1[builtins.str, builtins.str]"
362+
# reveal_type(c)
363+
[builtins fixtures/tuple.pyi]
364+
337365
[case testTypeVarDefaultsTypeAlias1]
338366
# flags: --disallow-any-generics
339367
from typing import Any, Dict, List, Tuple, TypeVar, Union

0 commit comments

Comments
 (0)