Skip to content

Commit 403a645

Browse files
committed
WIP
1 parent f877767 commit 403a645

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]
@@ -349,6 +357,26 @@ def func_c4(
349357
reveal_type(m) # N: Revealed type is "__main__.ClassC4[builtins.int, builtins.float]"
350358
[builtins fixtures/tuple.pyi]
351359

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+
352380
[case testTypeVarDefaultsTypeAlias1]
353381
# flags: --disallow-any-generics
354382
from typing import Any, Dict, List, Tuple, TypeVar, Union

0 commit comments

Comments
 (0)