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 2020-01-06.19:27:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1578338847.26.0.00979384316229.issue39235@roundup.psfhosted.org>
In-reply-to
Content
A normal generator expression like (i for i in a) produces the following AST:

Module(
    body=[
        Expr(
            value=GeneratorExp(
                elt=Name(
                    id="i", ctx=Load(), lineno=1, col_offset=1, end_lineno=1, end_col_offset=2
                ),
                generators=[
                    comprehension(
                        target=Name(
                            id="i",
                            ctx=Store(),
                            lineno=1,
                            col_offset=7,
                            end_lineno=1,
                            end_col_offset=8,
                        ),
                        iter=Name(
                            id="a",
                            ctx=Load(),
                            lineno=1,
                            col_offset=12,
                            end_lineno=1,
                            end_col_offset=13,
                        ),
                        ifs=[],
                        is_async=0,
                    )
                ],
                lineno=1,
                *col_offset=0,*
                end_lineno=1,
                *end_col_offset=14,*
            ),
            lineno=1,
            col_offset=0,
            end_lineno=1,
            end_col_offset=14,
        )
    ],
    type_ignores=[],
)

But when calling a function with a generator expression as an argument, something is off:

Module(
    body=[
        Expr(
            value=Call(
                func=Name(
                    id="f", ctx=Load(), lineno=1, col_offset=0, end_lineno=1, end_col_offset=1
                ),
                args=[
                    GeneratorExp(
                        elt=Name(
                            id="i",
                            ctx=Load(),
                            lineno=1,
                            col_offset=2,
                            end_lineno=1,
                            end_col_offset=3,
                        ),
                        generators=[
                            comprehension(
                                target=Name(
                                    id="i",
                                    ctx=Store(),
                                    lineno=1,
                                    col_offset=8,
                                    end_lineno=1,
                                    end_col_offset=9,
                                ),
                                iter=Name(
                                    id="a",
                                    ctx=Load(),
                                    lineno=1,
                                    col_offset=13,
                                    end_lineno=1,
                                    end_col_offset=14,
                                ),
                                ifs=[],
                                is_async=0,
                            )
                        ],
                        lineno=1,
                        *col_offset=1,*
                        end_lineno=1,
                        *end_col_offset=2,*
                    )
                ],
                keywords=[],
                lineno=1,
                col_offset=0,
                end_lineno=1,
                end_col_offset=15,
            ),
            lineno=1,
            col_offset=0,
            end_lineno=1,
            end_col_offset=15,
        )
    ],
    type_ignores=[],
)


I'm not sure if this is intentional or not, because there is a call to copy_location in Python/ast.c:3149. If this call to copy_location is removed, the inconsistency goes away.
History
Date User Action Args
2020-01-06 19:27:27lys.nikolaousetrecipients: + lys.nikolaou
2020-01-06 19:27:27lys.nikolaousetmessageid: <1578338847.26.0.00979384316229.issue39235@roundup.psfhosted.org>
2020-01-06 19:27:27lys.nikolaoulinkissue39235 messages
2020-01-06 19:27:27lys.nikolaoucreate