-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Finer-grained errors, ala PEP 657? #90
Comments
Do you want:
|
@15r10nk I'm curious, do you have any idea how Python computes both ranges? I don't see extra positions in the instructions and it's not trivial for it to know which other instruction to look at. |
I guess 1+2. I have an iPython front end mode in Emacs I'm working on, so I'd be able to use it even before iPython adopts it for their In terms of computing the finer range, CPython does something pretty simple. I'm not sure how it gets the larger range to begin with, and how that compares to what you do with |
Ah, I didn't expect that they would parse the AST, I thought they only used the positions in instructions.
Positions are stored in bytecode instructions
Since Python 3.11, executing uses those stored positions. For (2), you should be able to pretty much copy paste the CPython code since |
It's gotten more complicated in 3.13. I suppose it would be possible (if inefficient) to ask for the |
PEP 657 added "fine-grained errors" which are similar to executing's AST-level
text_range
. But the default python traceback printing goes further, employing two types of error markers,^
and~
. The latter is a "secondary" marker used for further detailed refinement for exceptions involving binary and indexing operators. Example:File fge.py
Produces:
while executing (here in iPython), shows:
One way to support this secondary refinement in a backwards-compatible way would be with an additional method
text_range_secondary
that computes the sub-region withintext_range
(if any) that could be highlighted distinctly.The text was updated successfully, but these errors were encountered: