Skip to content

Commit f19a7f7

Browse files
🐛 Fixed 'missing keys' not being reported
1 parent c7824be commit f19a7f7

File tree

1 file changed

+14
-19
lines changed

1 file changed

+14
-19
lines changed

mypy/messages.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,30 +1612,25 @@ def unexpected_typeddict_keys(
16121612
expected_set = set(expected_keys)
16131613
if not typ.is_anonymous():
16141614
# Generate simpler messages for some common special cases.
1615-
if actual_set < expected_set:
1616-
# Use list comprehension instead of set operations to preserve order.
1617-
missing = [key for key in expected_keys if key not in actual_set]
1615+
# Use list comprehension instead of set operations to preserve order.
1616+
missing = [key for key in expected_keys if key not in actual_set]
1617+
self.fail(
1618+
"Missing {} for TypedDict {}".format(
1619+
format_key_list(missing, short=True), format_type(typ)
1620+
),
1621+
context,
1622+
code=codes.TYPEDDICT_ITEM,
1623+
)
1624+
extra = [key for key in actual_keys if key not in expected_set]
1625+
if extra:
16181626
self.fail(
1619-
"Missing {} for TypedDict {}".format(
1620-
format_key_list(missing, short=True), format_type(typ)
1627+
"Extra {} for TypedDict {}".format(
1628+
format_key_list(extra, short=True), format_type(typ)
16211629
),
16221630
context,
1623-
code=codes.TYPEDDICT_ITEM,
1631+
code=codes.TYPPEDICT_UNKNOWN_KEY,
16241632
)
16251633
return
1626-
else:
1627-
extra = [key for key in actual_keys if key not in expected_set]
1628-
if extra:
1629-
# If there are both extra and missing keys, only report extra ones for
1630-
# simplicity.
1631-
self.fail(
1632-
"Extra {} for TypedDict {}".format(
1633-
format_key_list(extra, short=True), format_type(typ)
1634-
),
1635-
context,
1636-
code=codes.TYPPEDICT_UNKNOWN_KEY,
1637-
)
1638-
return
16391634
found = format_key_list(actual_keys, short=True)
16401635
if not expected_keys:
16411636
self.fail(f"Unexpected TypedDict {found}", context)

0 commit comments

Comments
 (0)