Skip to content

Commit c7b9670

Browse files
committed
Add tests for namedtuple and typeddict (both were unsupported, reported in python#17686
1 parent 1fed961 commit c7b9670

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

test-data/unit/check-python312.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -2043,7 +2043,7 @@ b: tuple[*tuple[int, ...], *tuple[int, ...]] # E: More than one Unpack in a typ
20432043
[builtins fixtures/tuple.pyi]
20442044
[typing fixtures/typing-full.pyi]
20452045

2046-
[case testPEP695TypeVarDefaultAliases]
2046+
[case testPEP695TypeVarConstraintsDefaultAliases]
20472047
from typing_extensions import TypeVar
20482048

20492049
type K = int

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

+40-3
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ a: MyA = A(None, 10)
748748
reveal_type(a.a) # N: Revealed type is "Union[builtins.int, None]"
749749
[builtins fixtures/tuple.pyi]
750750

751-
[case testTypeVarDefaultAliasesTypeAliasType]
751+
[case testTypeVarConstraintsDefaultAliasesTypeAliasType]
752752
from typing_extensions import TypeAliasType, TypeVar
753753

754754
K = TypeAliasType("K", int)
@@ -759,7 +759,7 @@ T2 = TypeVar("T2", str, K, default=V)
759759
T3 = TypeVar("T3", str, L, default=L)
760760
[builtins fixtures/tuple.pyi]
761761

762-
[case testTypeVarDefaultAliasesImplicitAlias]
762+
[case testTypeVarConstraintsDefaultAliasesImplicitAlias]
763763
from typing_extensions import TypeVar
764764

765765
K = int
@@ -770,7 +770,7 @@ T2 = TypeVar("T2", str, K, default=V)
770770
T3 = TypeVar("T3", str, L, default=L)
771771
[builtins fixtures/tuple.pyi]
772772

773-
[case testTypeVarDefaultAliasesExplicitAlias]
773+
[case testTypeVarConstraintsDefaultAliasesExplicitAlias]
774774
from typing_extensions import TypeAlias, TypeVar
775775

776776
K: TypeAlias = int
@@ -780,3 +780,40 @@ T1 = TypeVar("T1", str, K, default=K)
780780
T2 = TypeVar("T2", str, K, default=V)
781781
T3 = 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

Comments
 (0)