[ty] Improve diagnostics for syntax errors in forward annotations (#25158)
## Summary
Fixes https://github.com/astral-sh/ty/issues/1627.
Here's an example diagnostic with the current release of ty:
<img width="2286" height="286" alt="image"
src="https://github.com/user-attachments/assets/46ab9154-aaf0-4451-b301-5ff12fcd8507"
/>
On this branch, this diagnostic becomes:
<img width="1464" height="408" alt="image"
src="https://github.com/user-attachments/assets/449e0b6c-58d2-4501-91df-c267db6f48ca"
/>
The exact span of the node that creates the syntax error is now retained
and highlighted in the diagnostic.
## Implementation
Propagating the range of the node inside the string annotation into the
diagnostic is trivial. However, naively implementing that quickly
revealed that this would make diagnostics like this unsuppressable:
```py
x: """list[
yield from range(42)
]"""
```
The primary range of the diagnostic is now specifically the `yield from
range(42)` part of the string rather than the string node as a whole.
But I cannot add a `ty: ignore` comment that is either on or above the
`yield from range(42)` part of the string -- the "comment" there would
just become part of the string.
This PR also improves the consistency of our parser error messages in
general when it comes to capitalization.
## Test Plan
Mdtests extended and updated
---------
Co-authored-by: Micha Reiser <micha@reiser.io> A
Alex Waygood committed
366fe21ba369ccdd01eb99c1043c9a969c99230b
Parent: e2e1e64
Committed by GitHub <noreply@github.com>
on 5/28/2026, 10:51:20 AM