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.parse gives wrong position (col_offset) for some BinOp-s #62574
Comments
When parsing following program: 1+2-3 ast.parse gives col_offset=3 to outermost BinOp (as shown by the attached test script). Correct col_offset would be 0 for both BinOp-s |
Here's a patch that corrects col_offset for binops in both the ast module and in the compiler proper. I've incorporated Aivar's test into test_ast.py; if there are test suites for compile.c please let me know and I can add something there too. |
FWIW, in my opinion the col_offsets of the two nodes should be 1 and 3, respectively (the positions of the operators). |
I am not sure that changes in compile.c are needed now. Python/Python-ast.c is generated file. And perhaps it would be better to fix CST instead of AST. |
Pablo, Ivan: this old bug is able CST and AST, things that you know. You may want to have a look ;-) Note: This bug is discussed in https://twitter.com/cfbolz/status/1146866203975139328 |
This would not match the documentation:
|
Such change was committed once, but it was quickly reverted because it was not well discussed and contradicts the documentation. |
OK, fair enough. That means right now there is no way to find the position of the operator using the ast module at the moment, correct? |
It is between the end position of the left operand and the start position of the right operand. |
I think the attached patch fixes the problem. Will create a pull request soon. |
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: