File tree 3 files changed +31
-2
lines changed 3 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -152,6 +152,8 @@ def visit_typeddict_type(self, left: TypedDictType) -> bool:
152
152
if isinstance (self .right , TypedDictType ):
153
153
if left .items .keys () != self .right .items .keys ():
154
154
return False
155
+ if left .required_keys != self .right .required_keys :
156
+ return False
155
157
for (_ , left_item_type , right_item_type ) in left .zip (self .right ):
156
158
if not is_identical_type (left_item_type , right_item_type ):
157
159
return False
@@ -407,7 +409,8 @@ def visit_tuple_type(self, typ: TupleType) -> SnapshotItem:
407
409
def visit_typeddict_type (self , typ : TypedDictType ) -> SnapshotItem :
408
410
items = tuple ((key , snapshot_type (item_type ))
409
411
for key , item_type in typ .items .items ())
410
- return ('TypedDictType' , items )
412
+ required = tuple (sorted (typ .required_keys ))
413
+ return ('TypedDictType' , items , required )
411
414
412
415
def visit_union_type (self , typ : UnionType ) -> SnapshotItem :
413
416
# Sort and remove duplicates so that we can use equality to test for
Original file line number Diff line number Diff line change @@ -261,7 +261,7 @@ def visit_assignment_stmt(self, o: AssignmentStmt) -> None:
261
261
elif isinstance (rvalue , CallExpr ) and isinstance (rvalue .analyzed , TypedDictExpr ):
262
262
# Depend on the underlying typeddict type
263
263
info = rvalue .analyzed .info
264
- assert ( info .typeddict_type is not None )
264
+ assert info .typeddict_type is not None
265
265
prefix = '%s.%s' % (self .scope .current_full_target (), info .name ())
266
266
self .add_type_dependencies (info .typeddict_type , target = make_trigger (prefix ))
267
267
else :
Original file line number Diff line number Diff line change @@ -592,3 +592,29 @@ p = Point(dict(x=42, y='lurr'))
592
592
[out]
593
593
__main__.Point
594
594
__main__.p
595
+
596
+ [case testTypedDict3]
597
+ from mypy_extensions import TypedDict
598
+ Point = TypedDict('Point', {'x': int, 'y': int})
599
+ p = Point(dict(x=42, y=1337))
600
+ [file next.py]
601
+ from mypy_extensions import TypedDict
602
+ Point = TypedDict('Point', {'x': int})
603
+ p = Point(dict(x=42))
604
+ [builtins fixtures/dict.pyi]
605
+ [out]
606
+ __main__.Point
607
+ __main__.p
608
+
609
+ [case testTypedDict4]
610
+ from mypy_extensions import TypedDict
611
+ Point = TypedDict('Point', {'x': int, 'y': int})
612
+ p = Point(dict(x=42, y=1337))
613
+ [file next.py]
614
+ from mypy_extensions import TypedDict
615
+ Point = TypedDict('Point', {'x': int, 'y': int}, total=False)
616
+ p = Point(dict(x=42, y=1337))
617
+ [builtins fixtures/dict.pyi]
618
+ [out]
619
+ __main__.Point
620
+ __main__.p
You can’t perform that action at this time.
0 commit comments