Skip to content

Commit 6965aa7

Browse files
committed
Handle changes to totality
1 parent bee66e0 commit 6965aa7

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

mypy/server/astdiff.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ def visit_typeddict_type(self, left: TypedDictType) -> bool:
152152
if isinstance(self.right, TypedDictType):
153153
if left.items.keys() != self.right.items.keys():
154154
return False
155+
if left.required_keys != self.right.required_keys:
156+
return False
155157
for (_, left_item_type, right_item_type) in left.zip(self.right):
156158
if not is_identical_type(left_item_type, right_item_type):
157159
return False
@@ -407,7 +409,8 @@ def visit_tuple_type(self, typ: TupleType) -> SnapshotItem:
407409
def visit_typeddict_type(self, typ: TypedDictType) -> SnapshotItem:
408410
items = tuple((key, snapshot_type(item_type))
409411
for key, item_type in typ.items.items())
410-
return ('TypedDictType', items)
412+
required = tuple(sorted(typ.required_keys))
413+
return ('TypedDictType', items, required)
411414

412415
def visit_union_type(self, typ: UnionType) -> SnapshotItem:
413416
# Sort and remove duplicates so that we can use equality to test for

mypy/server/deps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ def visit_assignment_stmt(self, o: AssignmentStmt) -> None:
261261
elif isinstance(rvalue, CallExpr) and isinstance(rvalue.analyzed, TypedDictExpr):
262262
# Depend on the underlying typeddict type
263263
info = rvalue.analyzed.info
264-
assert(info.typeddict_type is not None)
264+
assert info.typeddict_type is not None
265265
prefix = '%s.%s' % (self.scope.current_full_target(), info.name())
266266
self.add_type_dependencies(info.typeddict_type, target=make_trigger(prefix))
267267
else:

test-data/unit/diff.test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -592,3 +592,29 @@ p = Point(dict(x=42, y='lurr'))
592592
[out]
593593
__main__.Point
594594
__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

0 commit comments

Comments
 (0)