[ty] Improve diagnostics for syntax errors in forward annotations by AlexWaygood · Pull Request #25158 · astral-sh/ruff (original) (raw)
carljm removed their request for review
Co-authored-by: Micha Reiser micha@reiser.io
anishgirianish pushed a commit to anishgirianish/ruff that referenced this pull request
Summary
Fixes astral-sh/ty#1627.
Here's an example diagnostic with the current release of ty:
On this branch, this diagnostic becomes:
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:
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
[ Show hidden characters]({{ revealButtonHref }})