@@ -1612,30 +1612,25 @@ def unexpected_typeddict_keys(
1612
1612
expected_set = set (expected_keys )
1613
1613
if not typ .is_anonymous ():
1614
1614
# 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 :
1618
1626
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 )
1621
1629
),
1622
1630
context ,
1623
- code = codes .TYPEDDICT_ITEM ,
1631
+ code = codes .TYPPEDICT_UNKNOWN_KEY ,
1624
1632
)
1625
1633
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
1639
1634
found = format_key_list (actual_keys , short = True )
1640
1635
if not expected_keys :
1641
1636
self .fail (f"Unexpected TypedDict { found } " , context )
0 commit comments