Skip to content

Commit 2a4220c

Browse files
🐛 Early return in case there's missing or extra keys
1 parent f19a7f7 commit 2a4220c

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

mypy/messages.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1614,13 +1614,14 @@ def unexpected_typeddict_keys(
16141614
# Generate simpler messages for some common special cases.
16151615
# Use list comprehension instead of set operations to preserve order.
16161616
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-
)
1617+
if missing:
1618+
self.fail(
1619+
"Missing {} for TypedDict {}".format(
1620+
format_key_list(missing, short=True), format_type(typ)
1621+
),
1622+
context,
1623+
code=codes.TYPEDDICT_ITEM,
1624+
)
16241625
extra = [key for key in actual_keys if key not in expected_set]
16251626
if extra:
16261627
self.fail(
@@ -1630,6 +1631,8 @@ def unexpected_typeddict_keys(
16301631
context,
16311632
code=codes.TYPPEDICT_UNKNOWN_KEY,
16321633
)
1634+
if missing or extra:
1635+
# No need to check for further errors
16331636
return
16341637
found = format_key_list(actual_keys, short=True)
16351638
if not expected_keys:

0 commit comments

Comments
 (0)