File tree Expand file tree Collapse file tree 4 files changed +18
-4
lines changed Expand file tree Collapse file tree 4 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -526,6 +526,9 @@ Whereas reading an unknown value will generate the more generic/serious
526
526
# Error: TypedDict "Point" has no key "z" [typeddict-item]
527
527
_ = a[" z" ]
528
528
529
+ .. note ::
530
+
531
+ This error code is a sub-error code of a wider ``[typeddict-item] `` code.
529
532
530
533
Check that type of target is known [has-type]
531
534
---------------------------------------------
Original file line number Diff line number Diff line change @@ -84,8 +84,11 @@ def __str__(self) -> str:
84
84
TYPEDDICT_ITEM : Final = ErrorCode (
85
85
"typeddict-item" , "Check items when constructing TypedDict" , "General"
86
86
)
87
- TYPPEDICT_UNKNOWN_KEY : Final = ErrorCode (
88
- "typeddict-unknown-key" , "Check unknown keys when constructing TypedDict" , "General"
87
+ TYPEDDICT_UNKNOWN_KEY : Final = ErrorCode (
88
+ "typeddict-unknown-key" ,
89
+ "Check unknown keys when constructing TypedDict" ,
90
+ "General" ,
91
+ sub_code_of = TYPEDDICT_ITEM ,
89
92
)
90
93
HAS_TYPE : Final = ErrorCode (
91
94
"has-type" , "Check that type of reference can be determined" , "General"
Original file line number Diff line number Diff line change @@ -1652,7 +1652,7 @@ def unexpected_typeddict_keys(
1652
1652
format_key_list (extra , short = True ), format_type (typ )
1653
1653
),
1654
1654
context ,
1655
- code = codes .TYPPEDICT_UNKNOWN_KEY ,
1655
+ code = codes .TYPEDDICT_UNKNOWN_KEY ,
1656
1656
)
1657
1657
if missing or extra :
1658
1658
# No need to check for further errors
@@ -1693,7 +1693,7 @@ def typeddict_key_not_found(
1693
1693
context ,
1694
1694
)
1695
1695
else :
1696
- err_code = codes .TYPPEDICT_UNKNOWN_KEY if setitem else codes .TYPEDDICT_ITEM
1696
+ err_code = codes .TYPEDDICT_UNKNOWN_KEY if setitem else codes .TYPEDDICT_ITEM
1697
1697
self .fail (
1698
1698
f'TypedDict { format_type (typ )} has no key "{ item_name } "' , context , code = err_code
1699
1699
)
Original file line number Diff line number Diff line change @@ -481,6 +481,14 @@ not_exist = a['not_exist'] # type: ignore[typeddict-item]
481
481
[builtins fixtures/dict.pyi]
482
482
[typing fixtures/typing-typeddict.pyi]
483
483
484
+ [case testErrorCodeTypedDictSubCodeIgnore]
485
+ from typing_extensions import TypedDict
486
+ class D(TypedDict):
487
+ x: int
488
+ d: D = {'x': 1, 'y': 2} # type: ignore[typeddict-item]
489
+ [builtins fixtures/dict.pyi]
490
+ [typing fixtures/typing-typeddict.pyi]
491
+
484
492
[case testErrorCodeCannotDetermineType]
485
493
y = x # E: Cannot determine type of "x" [has-type] # E: Name "x" is used before definition [used-before-def]
486
494
reveal_type(y) # N: Revealed type is "Any"
You can’t perform that action at this time.
0 commit comments