Author lys.nikolaou
Recipients lys.nikolaou
Date 2019-12-17.21:32:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576618328.23.0.851602684205.issue39080@roundup.psfhosted.org>
In-reply-to
Content
When a starred expression like *[0, 1] is parsed, the following AST gets generated:

Module(
    body=[
        Expr(
            value=Starred(
                value=List(
                    elts=[
                        Constant(
                            value=0,
                            kind=None,
                            lineno=1,
                            col_offset=2,
                            end_lineno=1,
                            end_col_offset=3,
                        ),
                        Constant(
                            value=1,
                            kind=None,
                            lineno=1,
                            col_offset=5,
                            end_lineno=1,
                            end_col_offset=6,
                        ),
                    ],
                    ctx=Load(),
                    lineno=1,
                    col_offset=1,
                    end_lineno=1,
                    end_col_offset=7,
                ),
                ctx=Load(),
                lineno=1,
                col_offset=0,
                end_lineno=1,
                end_col_offset=7,
            ),
            lineno=1,
            col_offset=0,
            end_lineno=1,
            end_col_offset=7,
        )
    ],
    type_ignores=[],
)


But, when a starred expression is an argument to a function call then the line/col info are wrong (end_col_offset is always equal to col_offset + 1):

Module(
    body=[
        Expr(
            value=Call(
                func=Name(
                    id="f", ctx=Load(), lineno=1, col_offset=0, end_lineno=1, end_col_offset=1
                ),
                args=[
                    Starred(
                        value=List(
                            elts=[
                                Constant(
                                    value=0,
                                    kind=None,
                                    lineno=1,
                                    col_offset=4,
                                    end_lineno=1,
                                    end_col_offset=5,
                                ),
                                Constant(
                                    value=1,
                                    kind=None,
                                    lineno=1,
                                    col_offset=7,
                                    end_lineno=1,
                                    end_col_offset=8,
                                ),
                            ],
                            ctx=Load(),
                            lineno=1,
                            col_offset=3,
                            end_lineno=1,
                            end_col_offset=9,
                        ),
                        ctx=Load(),
                        lineno=1,
                        col_offset=2,
                        end_lineno=1,
                        end_col_offset=9,
                    )
                ],
                keywords=[],
                lineno=1,
                col_offset=0,
                end_lineno=1,
                end_col_offset=10,
            ),
            lineno=1,
            col_offset=0,
            end_lineno=1,
            end_col_offset=10,
        )
    ],
    type_ignores=[],
)
History
Date User Action Args
2019-12-17 21:32:08lys.nikolaousetrecipients: + lys.nikolaou
2019-12-17 21:32:08lys.nikolaousetmessageid: <1576618328.23.0.851602684205.issue39080@roundup.psfhosted.org>
2019-12-17 21:32:08lys.nikolaoulinkissue39080 messages
2019-12-17 21:32:08lys.nikolaoucreate