Commit e73d952
authored
[ty] Include inferred type in
## Summary
Closes astral-sh/ty#3271
When subscripting a union or intersection of TypedDicts with an invalid
key, the concise diagnostic message now includes the source expression
and its full inferred type. This lets programmatic consumers of ty's
output distinguish between:
1. Key invalid on one branch of a union — may be intentional (e.g.
probing for a key that only exists on some branches)
2. Key truly invalid on a single-typed variable — likely a bug
### Before
```
file.py:19:14: error[invalid-key] Unknown key "foo" for TypedDict `DictB`
file.py:22:14: error[invalid-key] Unknown key "bar" for TypedDict `DictA`
```
Both errors look identical in structure — there is no way to tell from
concise output that line 19 involves a union type while line 22 does
not.
### After
```
file.py:19:14: error[invalid-key] Unknown key "foo" for TypedDict `DictB` (`resp` has type `DictA | DictB`)
file.py:22:14: error[invalid-key] Unknown key "bar" for TypedDict `DictA`
```
The source expression name is used (e.g. `resp`, `obj.data`), making the
message immediately understandable. The full (non-concise) diagnostic
output is unchanged — it already showed the union/intersection context
via a secondary annotation.
## Test Plan
- Updated 3 existing mdtest assertions in `typed_dict.md` to verify the
new concise message format for union and intersection cases
- All 330 tests in `ty_python_semantic` pass
- Clippy clean
- Manually verified concise output on the reproduction from the linked
issueinvalid-key concise diagnostic for union/intersection TypedDicts (#24693)1 parent 80feb29 commit e73d952
2 files changed
Lines changed: 13 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1873 | 1873 | | |
1874 | 1874 | | |
1875 | 1875 | | |
1876 | | - | |
| 1876 | + | |
1877 | 1877 | | |
1878 | 1878 | | |
1879 | 1879 | | |
| |||
1928 | 1928 | | |
1929 | 1929 | | |
1930 | 1930 | | |
1931 | | - | |
| 1931 | + | |
1932 | 1932 | | |
1933 | 1933 | | |
1934 | 1934 | | |
1935 | 1935 | | |
1936 | 1936 | | |
1937 | 1937 | | |
1938 | 1938 | | |
1939 | | - | |
| 1939 | + | |
1940 | 1940 | | |
1941 | 1941 | | |
1942 | 1942 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5248 | 5248 | | |
5249 | 5249 | | |
5250 | 5250 | | |
5251 | | - | |
5252 | | - | |
5253 | | - | |
| 5251 | + | |
| 5252 | + | |
| 5253 | + | |
| 5254 | + | |
| 5255 | + | |
| 5256 | + | |
| 5257 | + | |
| 5258 | + | |
| 5259 | + | |
| 5260 | + | |
5254 | 5261 | | |
5255 | 5262 | | |
5256 | 5263 | | |
| |||
0 commit comments