@@ -748,7 +748,7 @@ a: MyA = A(None, 10)
748748reveal_type(a.a) # N: Revealed type is "Union[builtins.int, None]"
749749[builtins fixtures/tuple.pyi]
750750
751- [case testTypeVarDefaultAliasesTypeAliasType ]
751+ [case testTypeVarConstraintsDefaultAliasesTypeAliasType ]
752752from typing_extensions import TypeAliasType, TypeVar
753753
754754K = TypeAliasType("K", int)
@@ -759,7 +759,7 @@ T2 = TypeVar("T2", str, K, default=V)
759759T3 = TypeVar("T3", str, L, default=L)
760760[builtins fixtures/tuple.pyi]
761761
762- [case testTypeVarDefaultAliasesImplicitAlias ]
762+ [case testTypeVarConstraintsDefaultAliasesImplicitAlias ]
763763from typing_extensions import TypeVar
764764
765765K = int
@@ -770,7 +770,7 @@ T2 = TypeVar("T2", str, K, default=V)
770770T3 = TypeVar("T3", str, L, default=L)
771771[builtins fixtures/tuple.pyi]
772772
773- [case testTypeVarDefaultAliasesExplicitAlias ]
773+ [case testTypeVarConstraintsDefaultAliasesExplicitAlias ]
774774from typing_extensions import TypeAlias, TypeVar
775775
776776K: TypeAlias = int
@@ -780,3 +780,40 @@ T1 = TypeVar("T1", str, K, default=K)
780780T2 = TypeVar("T2", str, K, default=V)
781781T3 = TypeVar("T3", str, L, default=L)
782782[builtins fixtures/tuple.pyi]
783+
784+ [case testTypeVarConstraintsDefaultSpecialTypes]
785+ from typing import NamedTuple
786+ from typing_extensions import TypedDict, TypeVar
787+
788+ class TD(TypedDict):
789+ foo: str
790+
791+ class NT(NamedTuple):
792+ foo: str
793+
794+ T1 = TypeVar("T1", str, TD, default=TD)
795+ T2 = TypeVar("T2", str, NT, default=NT)
796+ [builtins fixtures/tuple.pyi]
797+
798+ [case testTypeVarConstraintsDefaultSpecialTypesGeneric]
799+ from typing import Generic, NamedTuple
800+ from typing_extensions import TypedDict, TypeVar
801+
802+ T = TypeVar("T")
803+
804+ class TD(TypedDict, Generic[T]):
805+ foo: T
806+ class TD2(TD[int]): pass
807+ class TD3(TD[int]):
808+ bar: str
809+
810+ class NT(NamedTuple, Generic[T]):
811+ foo: T
812+ class NT2(NT[int]): pass
813+
814+ T1 = TypeVar("T1", str, TD[int], default=TD[int])
815+ T2 = TypeVar("T2", str, NT[int], default=NT[int])
816+ T3 = TypeVar("T3", str, TD2, default=TD[int])
817+ T4 = TypeVar("T4", str, TD3, default=TD[int]) # E: TypeVar default must be one of the constraint types
818+ T5 = TypeVar("T5", str, NT2, default=NT[int]) # E: TypeVar default must be one of the constraint types
819+ [builtins fixtures/tuple.pyi]
0 commit comments