-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
ast.Call end_lineno is defined and returns None #84903
Comments
Reporting an issue from xonsh/xonsh#3581; boils down to, ast.Call used to not define end_lineno in 3.8: py -3.8 -c 'import ast; type(ast.Call().end_lineno)' Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: 'Call' object has no attribute 'end_lineno' However in 3.9 is defined with None: py -3.9 -c 'import ast; type(ast.Call().end_lineno)' This messes with some other operations in ast, namely https://github.com/python/cpython/blob/master/Lib/ast.py#L233 |
The issue is not limited to ast.Call. Other AST nodes are also affected (e.g. ast.BinOp). It's also not limited to end_lineno attribute. The same applies to end_col_offset. |
This is because the 'end_lineno' and 'end_col_offset' are declared as optional attributes in the ASDL spec. The commit 'b7e9525f9c7ef02a1d2ad8253afdeb733b0951d4' made all optional fields and attributes auto initalized with None. |
See here for the complete spec: https://docs.python.org/3.9/library/ast.html#abstract-grammar |
:/ I'm terribly sorry for that, I just sent a PR without refreshing the tab. |
There's current expectation in a lot of linters / code formatters that the *lineno and *col_offset attributes will be missing if they are not attached to the node setting them to None is going to break a lot of those, if possible I'd suggest going back to when they were missing |
'lineno' and 'col_offset' will never be none, since both are declared as normal integers. But on the other hand, 'end_lineno' and 'end_col_offset' are declared as optional integers which would make sense to auto initalize them with *None*, and I dont think it would ever break some code that complies with the ASDL declaration. |
Actually, Xonsh (http://github.com/xonsh/xonsh) tests show that keyword AST nodes are missing 'lineno' attribute, but that could be our fault. |
Yes, our fault. Sorry for the noise. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: