@@ -749,6 +749,7 @@ reveal_type(a.a) # N: Revealed type is "Union[builtins.int, None]"
749
749
[builtins fixtures/tuple.pyi]
750
750
751
751
[case testTypeVarConstraintsDefaultAliasesTypeAliasType]
752
+ from typing import Generic
752
753
from typing_extensions import TypeAliasType, TypeVar
753
754
754
755
K = TypeAliasType("K", int)
@@ -757,6 +758,17 @@ L = TypeAliasType("L", list[int])
757
758
T1 = TypeVar("T1", str, K, default=K)
758
759
T2 = TypeVar("T2", str, K, default=V)
759
760
T3 = TypeVar("T3", str, L, default=L)
761
+
762
+ class A1(Generic[T1]):
763
+ x: T1
764
+ class A2(Generic[T2]):
765
+ x: T2
766
+ class A3(Generic[T3]):
767
+ x: T3
768
+
769
+ reveal_type(A1().x) # N: Revealed type is "builtins.int"
770
+ reveal_type(A2().x) # N: Revealed type is "builtins.int"
771
+ reveal_type(A3().x) # N: Revealed type is "builtins.list[builtins.int]"
760
772
[builtins fixtures/tuple.pyi]
761
773
762
774
[case testTypeVarConstraintsDefaultAliasesImplicitAlias]
@@ -782,7 +794,7 @@ T3 = TypeVar("T3", str, L, default=L)
782
794
[builtins fixtures/tuple.pyi]
783
795
784
796
[case testTypeVarConstraintsDefaultSpecialTypes]
785
- from typing import NamedTuple
797
+ from typing import Generic, NamedTuple
786
798
from typing_extensions import TypedDict, TypeVar
787
799
788
800
class TD(TypedDict):
@@ -793,6 +805,14 @@ class NT(NamedTuple):
793
805
794
806
T1 = TypeVar("T1", str, TD, default=TD)
795
807
T2 = TypeVar("T2", str, NT, default=NT)
808
+
809
+ class A1(Generic[T1]):
810
+ x: T1
811
+ class A2(Generic[T2]):
812
+ x: T2
813
+
814
+ reveal_type(A1().x) # N: Revealed type is "TypedDict('__main__.TD', {'foo': builtins.str})"
815
+ reveal_type(A2().x) # N: Revealed type is "Tuple[builtins.str, fallback=__main__.NT]"
796
816
[builtins fixtures/tuple.pyi]
797
817
798
818
[case testTypeVarConstraintsDefaultSpecialTypesGeneric]
@@ -816,4 +836,15 @@ T2 = TypeVar("T2", str, NT[int], default=NT[int])
816
836
T3 = TypeVar("T3", str, TD2, default=TD[int])
817
837
T4 = TypeVar("T4", str, TD3, default=TD[int]) # E: TypeVar default must be one of the constraint types
818
838
T5 = TypeVar("T5", str, NT2, default=NT[int]) # E: TypeVar default must be one of the constraint types
839
+
840
+ class A1(Generic[T1]):
841
+ x: T1
842
+ class A2(Generic[T2]):
843
+ x: T2
844
+ class A3(Generic[T3]):
845
+ x: T3
846
+
847
+ reveal_type(A1().x) # N: Revealed type is "TypedDict('__main__.TD', {'foo': builtins.int})"
848
+ reveal_type(A2().x) # N: Revealed type is "Tuple[builtins.int, fallback=__main__.NT[builtins.int]]"
849
+ reveal_type(A3().x) # N: Revealed type is "TypedDict('__main__.TD', {'foo': builtins.int})"
819
850
[builtins fixtures/tuple.pyi]
0 commit comments