[ty] Add backreferences to TypedDict items in diagnostics (#20262)

## Summary

Add backreferences to the original item declaration in TypedDict
diagnostics.

Thanks to @AlexWaygood for the suggestion.

## Test Plan

Updated snapshots
This commit is contained in:
David Peter 2025-09-05 12:38:37 +02:00 committed by GitHub
parent 9e45bfa9fd
commit 8ade6c4eaf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 146 additions and 149 deletions

View file

@ -108,6 +108,16 @@ error[invalid-assignment]: Invalid assignment to key "age" with declared type `i
20 |
21 | def write_to_non_existing_key(person: Person):
|
info: Item declaration
--> src/mdtest_snippet.py:5:5
|
3 | class Person(TypedDict):
4 | name: str
5 | age: int | None
| --------------- Item declared here
6 |
7 | def access_invalid_literal_string_key(person: Person):
|
info: rule `invalid-assignment` is enabled by default
```
@ -151,6 +161,14 @@ error[invalid-assignment]: Cannot assign to key "id" on TypedDict `Employee`
| |
| TypedDict `Employee`
|
info: Item declaration
--> src/mdtest_snippet.py:29:5
|
28 | class Employee(TypedDict):
29 | id: ReadOnly[int]
| ----------------- Read-only item declared here
30 | name: str
|
info: rule `invalid-assignment` is enabled by default
```