Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.1k
Commitce14043
authored
Use more precise context for TypedDict plugin errors (#18293)
Fixes#12271Uses an applicable argument expression as the error context instead ofthe overall CallExpr.**Given:**```python# flags: --pretty --show-column-numberfrom typing import TypedDictclass A(TypedDict): x: inta: Ax.setdefault("y", 123)x.setdefault("x", "bad")# Non-TypedDict case for referenceb: 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)```1 parent973618a commitce14043
File tree
4 files changed
+40
-22
lines changed- mypy/plugins
- test-data/unit
4 files changed
+40
-22
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
| 307 | + | |
| 308 | + | |
308 | 309 | | |
309 | 310 | | |
310 | 311 | | |
311 | | - | |
| 312 | + | |
312 | 313 | | |
313 | 314 | | |
314 | 315 | | |
315 | 316 | | |
316 | 317 | | |
317 | 318 | | |
318 | 319 | | |
319 | | - | |
| 320 | + | |
320 | 321 | | |
321 | 322 | | |
322 | 323 | | |
323 | 324 | | |
324 | 325 | | |
325 | | - | |
| 326 | + | |
326 | 327 | | |
327 | 328 | | |
328 | 329 | | |
| |||
363 | 364 | | |
364 | 365 | | |
365 | 366 | | |
366 | | - | |
| 367 | + | |
| 368 | + | |
367 | 369 | | |
368 | 370 | | |
369 | 371 | | |
370 | | - | |
| 372 | + | |
371 | 373 | | |
372 | 374 | | |
373 | 375 | | |
374 | 376 | | |
375 | 377 | | |
376 | 378 | | |
377 | | - | |
| 379 | + | |
378 | 380 | | |
379 | 381 | | |
| 382 | + | |
380 | 383 | | |
381 | 384 | | |
382 | 385 | | |
383 | 386 | | |
384 | 387 | | |
385 | 388 | | |
386 | | - | |
| 389 | + | |
387 | 390 | | |
388 | 391 | | |
389 | 392 | | |
| |||
392 | 395 | | |
393 | 396 | | |
394 | 397 | | |
395 | | - | |
| 398 | + | |
396 | 399 | | |
397 | 400 | | |
398 | 401 | | |
| |||
409 | 412 | | |
410 | 413 | | |
411 | 414 | | |
412 | | - | |
| 415 | + | |
| 416 | + | |
413 | 417 | | |
414 | 418 | | |
415 | 419 | | |
416 | | - | |
| 420 | + | |
417 | 421 | | |
418 | 422 | | |
419 | 423 | | |
420 | 424 | | |
421 | 425 | | |
422 | 426 | | |
423 | | - | |
| 427 | + | |
424 | 428 | | |
425 | | - | |
| 429 | + | |
426 | 430 | | |
427 | 431 | | |
428 | 432 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
| 230 | + | |
230 | 231 | | |
231 | 232 | | |
232 | | - | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
233 | 243 | | |
234 | 244 | | |
235 | 245 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1909 | 1909 | | |
1910 | 1910 | | |
1911 | 1911 | | |
1912 | | - | |
1913 | | - | |
| 1912 | + | |
| 1913 | + | |
| 1914 | + | |
1914 | 1915 | | |
1915 | 1916 | | |
1916 | 1917 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1747 | 1747 | | |
1748 | 1748 | | |
1749 | 1749 | | |
1750 | | - | |
1751 | | - | |
| 1750 | + | |
| 1751 | + | |
| 1752 | + | |
1752 | 1753 | | |
1753 | 1754 | | |
1754 | 1755 | | |
| |||
2614 | 2615 | | |
2615 | 2616 | | |
2616 | 2617 | | |
2617 | | - | |
2618 | | - | |
| 2618 | + | |
| 2619 | + | |
| 2620 | + | |
2619 | 2621 | | |
2620 | 2622 | | |
2621 | 2623 | | |
| |||
3726 | 3728 | | |
3727 | 3729 | | |
3728 | 3730 | | |
3729 | | - | |
3730 | | - | |
| 3731 | + | |
| 3732 | + | |
| 3733 | + | |
3731 | 3734 | | |
3732 | 3735 | | |
3733 | 3736 | | |
| |||
0 commit comments
Comments
(0)