msg192394 - (view) |
Author: Aivar Annamaa (Aivar.Annamaa) * |
Date: 2013-07-06 09:35 |
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 |
|
|
msg216696 - (view) |
Author: Sam Kimbrel (sam.kimbrel) * |
Date: 2014-04-17 15:19 |
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. |
|
|
msg347294 - (view) |
Author: Carl Friedrich Bolz-Tereick (Carl.Friedrich.Bolz) * |
Date: 2019-07-04 20:15 |
FWIW, in my opinion the col_offsets of the two nodes should be 1 and 3, respectively (the positions of the operators). |
|
|
msg347313 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2019-07-05 08:46 |
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. |
|
|
msg347319 - (view) |
Author: STINNER Victor (vstinner) *  |
Date: 2019-07-05 09:15 |
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 |
|
|
msg347320 - (view) |
Author: Aivar Annamaa (Aivar.Annamaa) * |
Date: 2019-07-05 09:38 |
> in my opinion the col_offsets of the two nodes should be 1 and 3, respectively (the positions of the operators) This would not match the documentation: > one can get the source segment of a one-line expression node using source_line[node.col_offset : node.end_col_offset] |
|
|
msg347324 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2019-07-05 09:51 |
> in my opinion the col_offsets of the two nodes should be 1 and 3, respectively (the positions of the operators) Such change was committed once, but it was quickly reverted because it was not well discussed and contradicts the documentation. |
|
|
msg347325 - (view) |
Author: Carl Friedrich Bolz-Tereick (Carl.Friedrich.Bolz) * |
Date: 2019-07-05 10:02 |
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? |
|
|
msg347326 - (view) |
Author: Serhiy Storchaka (serhiy.storchaka) *  |
Date: 2019-07-05 10:11 |
It is between the end position of the left operand and the start position of the right operand. |
|
|
msg347370 - (view) |
Author: Carl Friedrich Bolz-Tereick (Carl.Friedrich.Bolz) * |
Date: 2019-07-05 19:32 |
I think the attached patch fixes the problem. Will create a pull request soon. |
|
|
msg347509 - (view) |
Author: Ivan Levkivskyi (levkivskyi) *  |
Date: 2019-07-08 21:17 |
New changeset 110a47c4f42cf4db88edc1876899fff8f05190fb by Ivan Levkivskyi (Carl Friedrich Bolz-Tereick) in branch 'master': bpo-18374: fix wrong col_offset of some ast.BinOp instances (GH-14607) https://github.com/python/cpython/commit/110a47c4f42cf4db88edc1876899fff8f05190fb |
|
|
msg347510 - (view) |
Author: miss-islington (miss-islington) |
Date: 2019-07-08 21:41 |
New changeset c7be35c2abd598f02a633879133caec356593241 by Miss Islington (bot) in branch '3.8': bpo-18374: fix wrong col_offset of some ast.BinOp instances (GH-14607) https://github.com/python/cpython/commit/c7be35c2abd598f02a633879133caec356593241 |
|
|
msg347554 - (view) |
Author: Ivan Levkivskyi (levkivskyi) *  |
Date: 2019-07-09 12:20 |
New changeset 430a9f44fe22f029ae8cfeecb46621d7e199414b by Ivan Levkivskyi (Carl Friedrich Bolz-Tereick) in branch 'master': bpo-18374: fix tests to check the correct thing about line numbers (GH-14659) https://github.com/python/cpython/commit/430a9f44fe22f029ae8cfeecb46621d7e199414b |
|
|
msg347560 - (view) |
Author: Ivan Levkivskyi (levkivskyi) *  |
Date: 2019-07-09 13:29 |
New changeset 68bd9c5691c4899d21cc7fe6cce7cd22b2f5ccb0 by Ivan Levkivskyi (Miss Islington (bot)) in branch '3.8': bpo-18374: fix tests to check the correct thing about line numbers (GH-14659) (GH-14672) https://github.com/python/cpython/commit/68bd9c5691c4899d21cc7fe6cce7cd22b2f5ccb0 |
|
|