Skip to content

Commit c7824be

Browse files
✨ Added new Error to TypedDict
See: [#4617](#4617) This allows the following code to trigger the error `typeddict-unknown-key` ```python A = T.TypedDict("A", {"x": int}) def f(x: A) -> None: ... f({"x": 1, "y": "foo"}) ``` The user can then safely ignore this specific error at their disgression.
1 parent 98f1b00 commit c7824be

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

mypy/errorcodes.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ def __str__(self) -> str:
6767
TYPEDDICT_ITEM: Final = ErrorCode(
6868
"typeddict-item", "Check items when constructing TypedDict", "General"
6969
)
70+
TYPPEDICT_UNKNOWN_KEY: Final = ErrorCode(
71+
"typeddict-unknown-key", "Check unknown keys when constructing TypedDict", "General"
72+
)
7073
HAS_TYPE: Final = ErrorCode(
7174
"has-type", "Check that type of reference can be determined", "General"
7275
)

mypy/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1633,7 +1633,7 @@ def unexpected_typeddict_keys(
16331633
format_key_list(extra, short=True), format_type(typ)
16341634
),
16351635
context,
1636-
code=codes.TYPEDDICT_ITEM,
1636+
code=codes.TYPPEDICT_UNKNOWN_KEY,
16371637
)
16381638
return
16391639
found = format_key_list(actual_keys, short=True)

0 commit comments

Comments
 (0)