mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:16 +00:00
[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:
parent
9e45bfa9fd
commit
8ade6c4eaf
7 changed files with 146 additions and 149 deletions
|
@ -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
|
||||
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue