You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use more precise context for TypedDict plugin errors (#18293)
Fixes#12271
Uses an applicable argument expression as the error context instead of
the overall CallExpr.
**Given:**
```python
# flags: --pretty --show-column-number
from typing import TypedDict
class A(TypedDict):
x: int
a: A
x.setdefault("y", 123)
x.setdefault("x", "bad")
# Non-TypedDict case for reference
b: dict[str, int]
b.setdefault("x", "bad")
```
**Before:**
```
main.py:8:1: error: TypedDict "A" has no key "y" [typeddict-item]
a.setdefault("y", 123)
^~~~~~~~~~~~~~~~~~~~~~
main.py:9:1: error: Argument 2 to "setdefault" of "TypedDict" has incompatible type "str"; expected "int" [typeddict-item]
a.setdefault("x", "bad")
^~~~~~~~~~~~~~~~~~~~~~~~
main.py:13:19: error: Argument 2 to "setdefault" of "MutableMapping" has incompatible type "str"; expected "int" [arg-type]
b.setdefault("x", "bad")
^~~~~
Found 3 errors in 1 file (checked 1 source file)
```
**After:**
```
main.py:8:14: error: TypedDict "A" has no key "y" [typeddict-item]
a.setdefault("y", 123)
^~~
main.py:9:19: error: Argument 2 to "setdefault" of "TypedDict" has incompatible type "str"; expected "int" [typeddict-item]
a.setdefault("x", "bad")
^~~~~
main.py:13:19: error: Argument 2 to "setdefault" of "MutableMapping" has incompatible type "str"; expected "int" [arg-type]
b.setdefault("x", "bad")
^~~~~
Found 3 errors in 1 file (checked 1 source file)
```
0 commit comments