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
526526 # Error: TypedDict "Point" has no key "z" [typeddict-item]
527527 _ = a[" z" ]
528528
529+ .. note ::
530+
531+ This error code is a sub-error code of a wider ``[typeddict-item] `` code.
529532
530533Check that type of target is known [has-type]
531534---------------------------------------------
Original file line number Diff line number Diff line change @@ -84,8 +84,11 @@ def __str__(self) -> str:
8484TYPEDDICT_ITEM : Final = ErrorCode (
8585 "typeddict-item" , "Check items when constructing TypedDict" , "General"
8686)
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 ,
8992)
9093HAS_TYPE : Final = ErrorCode (
9194 "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(
16521652 format_key_list (extra , short = True ), format_type (typ )
16531653 ),
16541654 context ,
1655- code = codes .TYPPEDICT_UNKNOWN_KEY ,
1655+ code = codes .TYPEDDICT_UNKNOWN_KEY ,
16561656 )
16571657 if missing or extra :
16581658 # No need to check for further errors
@@ -1693,7 +1693,7 @@ def typeddict_key_not_found(
16931693 context ,
16941694 )
16951695 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
16971697 self .fail (
16981698 f'TypedDict { format_type (typ )} has no key "{ item_name } "' , context , code = err_code
16991699 )
Original file line number Diff line number Diff line change @@ -481,6 +481,14 @@ not_exist = a['not_exist'] # type: ignore[typeddict-item]
481481[builtins fixtures/dict.pyi]
482482[typing fixtures/typing-typeddict.pyi]
483483
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+
484492[case testErrorCodeCannotDetermineType]
485493y = x # E: Cannot determine type of "x" [has-type] # E: Name "x" is used before definition [used-before-def]
486494reveal_type(y) # N: Revealed type is "Any"
You can’t perform that action at this time.
0 commit comments