Message358304
While working on pegen, we came across an inconsistency on how line number and column offset info is stored for (el)if nodes. When parsing a very simple if-elif construct like
if a:
pass
elif b:
pass
the following parse tree gets generated:
Module(
body=[
If(
test=Name(id="a", ctx=Load(), lineno=1, col_offset=3, end_lineno=1, end_col_offset=4),
body=[Pass(lineno=2, col_offset=4, end_lineno=2, end_col_offset=8)],
orelse=[
If(
test=Name(
id="b", ctx=Load(), lineno=3, col_offset=5, end_lineno=3, end_col_offset=6
),
body=[Pass(lineno=4, col_offset=4, end_lineno=4, end_col_offset=8)],
orelse=[],
lineno=3,
col_offset=5,
end_lineno=4,
end_col_offset=8,
)
],
lineno=1,
col_offset=0,
end_lineno=4,
end_col_offset=8,
)
],
type_ignores=[],
)
There is the inconsistency that the column offset for the if statement is 0, thus the if statement starts with the keyword if, whereas the column offset for elif if 5, which means that the elif keyword is skipped.
As Guido suggests over at https://github.com/gvanrossum/pegen/issues/107#issuecomment-565135047 we could very easily change Python/ast.c so that the elif statement start with the elif keyword as well.
I have a PR ready! |
|
Date |
User |
Action |
Args |
2019-12-12 20:15:07 | lys.nikolaou | set | recipients:
+ lys.nikolaou |
2019-12-12 20:15:07 | lys.nikolaou | set | messageid: <1576181707.03.0.620704542473.issue39031@roundup.psfhosted.org> |
2019-12-12 20:15:06 | lys.nikolaou | link | issue39031 messages |
2019-12-12 20:15:06 | lys.nikolaou | create | |
|