This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lys.nikolaou
Recipients lys.nikolaou
Date 2019-12-12.20:15:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576181707.03.0.620704542473.issue39031@roundup.psfhosted.org>
In-reply-to
Content
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!
History
Date User Action Args
2019-12-12 20:15:07lys.nikolaousetrecipients: + lys.nikolaou
2019-12-12 20:15:07lys.nikolaousetmessageid: <1576181707.03.0.620704542473.issue39031@roundup.psfhosted.org>
2019-12-12 20:15:06lys.nikolaoulinkissue39031 messages
2019-12-12 20:15:06lys.nikolaoucreate