Skip to content

Commit

Permalink
✨ Added new Error to TypedDict
Browse files Browse the repository at this point in the history
See: [python#4617](python#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.
  • Loading branch information
JoaquimEsteves committed Nov 30, 2022
1 parent 98f1b00 commit c7824be
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions mypy/errorcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ def __str__(self) -> str:
TYPEDDICT_ITEM: Final = ErrorCode(
"typeddict-item", "Check items when constructing TypedDict", "General"
)
TYPPEDICT_UNKNOWN_KEY: Final = ErrorCode(
"typeddict-unknown-key", "Check unknown keys when constructing TypedDict", "General"
)
HAS_TYPE: Final = ErrorCode(
"has-type", "Check that type of reference can be determined", "General"
)
Expand Down
2 changes: 1 addition & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ def unexpected_typeddict_keys(
format_key_list(extra, short=True), format_type(typ)
),
context,
code=codes.TYPEDDICT_ITEM,
code=codes.TYPPEDICT_UNKNOWN_KEY,
)
return
found = format_key_list(actual_keys, short=True)
Expand Down

0 comments on commit c7824be

Please sign in to comment.