-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Add to AST location info for compound exception headers or keywords #129157
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-parser
type-feature
A feature request or enhancement
Comments
iritkatriel
changed the title
Add to AST location info for compound exception headers
Add to AST location info for compound exception headers or keywords
Jan 21, 2025
picnixz
added
type-feature
A feature request or enhancement
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
labels
Jan 21, 2025
On it |
pablogsal
added a commit
to pablogsal/cpython
that referenced
this issue
Jan 21, 2025
…pawn the first line
Let's settle on this one first and I will take the other in other PRs |
pablogsal
added a commit
to pablogsal/cpython
that referenced
this issue
Jan 22, 2025
…pawn the first line Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
pablogsal
added a commit
to pablogsal/cpython
that referenced
this issue
Jan 22, 2025
…pawn the first line Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
pablogsal
added a commit
to pablogsal/cpython
that referenced
this issue
Jan 22, 2025
…pawn the first line Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
pablogsal
added a commit
to pablogsal/cpython
that referenced
this issue
Jan 22, 2025
…pawn the first line
There's an analogous issue with for loops:
|
pablogsal
added a commit
to pablogsal/cpython
that referenced
this issue
Jan 22, 2025
…pawn the first line Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
interpreter-core
(Objects, Python, Grammar, and Parser dirs)
topic-parser
type-feature
A feature request or enhancement
The location information in the AST for a compound statement spans the whole body.
For example:
Output:
"Module(body=[With(items=[withitem(context_expr=Name(id='A', ctx=Load(), lineno=1, col_offset=5, end_lineno=1, end_col_offset=6), optional_vars=Name(id='cm', ctx=Store(), lineno=1, col_offset=10, end_lineno=1, end_col_offset=12))], body=[Expr(value=Constant(value=1, lineno=2, col_offset=4, end_lineno=2, end_col_offset=5), lineno=2, col_offset=4, end_lineno=2, end_col_offset=5), Expr(value=Constant(value=2, lineno=3, col_offset=4, end_lineno=3, end_col_offset=5), lineno=3, col_offset=4, end_lineno=3, end_col_offset=5), Expr(value=Constant(value=3, lineno=4, col_offset=4, end_lineno=4, end_col_offset=5), lineno=4, col_offset=4, end_lineno=4, end_col_offset=5)], lineno=1, col_offset=0, end_lineno=4, end_col_offset=5)])"
If
__enter__
or__exit__
of the context manager raises an exception, we don't want the location of the exception to span the entire body. Ideally it would be the location of thewith
keyword (my view) or the entirewith x as y
statement (@ericsnowcurrently's view). However, we don't have those locations in the AST so currently we hilight the location of the expression that creates the context manager:We have similar issue with
except
blocks and class definitions.Can we add location information of the keywords, or of the header of a compound expression, to the AST?
@pablogsal @lysnikolaou
Linked PRs
The text was updated successfully, but these errors were encountered: