@@ -1155,6 +1155,40 @@ def bad() -> int: ...
11551155td2 = A({"fn": bad, "val": 42}) # E: Incompatible types (expression has type "Callable[[], int]", TypedDict item "fn" has type "Callable[[], None]")
11561156[builtins fixtures/tuple.pyi]
11571157
1158+ [case testVariadicTypedDictExtending]
1159+ from typing import Tuple, Callable, Generic
1160+ from typing_extensions import TypeVarTuple, Unpack, TypedDict
1161+
1162+ Ts = TypeVarTuple("Ts")
1163+ class A(TypedDict, Generic[Unpack[Ts], T]):
1164+ fn: Callable[[Unpack[Ts]], None]
1165+ val: T
1166+
1167+ class B(A[Unpack[Ts], T]):
1168+ gn: Callable[[Unpack[Ts]], None]
1169+ vals: Tuple[Unpack[Ts]]
1170+
1171+ y: B[int, str]
1172+ reveal_type(y) # N: Revealed type is "TypedDict('__main__.B', {'fn': def (builtins.int), 'val': builtins.str, 'gn': def (builtins.int), 'vals': Tuple[builtins.int]})"
1173+ reveal_type(y["gn"]) # N: Revealed type is "def (builtins.int)"
1174+ reveal_type(y["vals"]) # N: Revealed type is "Tuple[builtins.int]"
1175+
1176+ z: B[Unpack[Tuple[int, ...]]]
1177+ reveal_type(z) # N: Revealed type is "TypedDict('__main__.B', {'fn': def (*builtins.int), 'val': builtins.int, 'gn': def (*builtins.int), 'vals': builtins.tuple[builtins.int, ...]})"
1178+ reveal_type(z["gn"]) # N: Revealed type is "def (*builtins.int)"
1179+
1180+ t: B[int, Unpack[Tuple[int, str]], str]
1181+ reveal_type(t) # N: Revealed type is "TypedDict('__main__.B', {'fn': def (builtins.int, builtins.int, builtins.str), 'val': builtins.str, 'gn': def (builtins.int, builtins.int, builtins.str), 'vals': Tuple[builtins.int, builtins.int, builtins.str]})"
1182+
1183+ def ftest(x: int, y: str) -> None: ...
1184+ def gtest(x: int, y: str) -> None: ...
1185+ td = B({"fn": ftest, "val": 42, "gn": gtest, "vals": (6, "7")})
1186+ reveal_type(td) # N: Revealed type is "TypedDict('__main__.B', {'fn': def (builtins.int, builtins.str), 'val': builtins.int, 'gn': def (builtins.int, builtins.str), 'vals': Tuple[builtins.int, builtins.str]})"
1187+
1188+ def gbad() -> int: ...
1189+ td2 = B({"fn": ftest, "val": 42, "gn": gbad, "vals": (6, "7")}) # E: Incompatible types (expression has type "Callable[[], int]", TypedDict item "gn" has type "Callable[[int, str], None]")
1190+ [builtins fixtures/tuple.pyi]
1191+
11581192[case testFixedUnpackWithRegularInstance]
11591193from typing import Tuple, Generic, TypeVar
11601194from typing_extensions import Unpack
0 commit comments