Skip to content

PEP 709: Comprehension iteration variable leaks into outer locals() #104619

Description

@JelleZijlstra

Code:

def __b():
    [__a for __b in [__b] for _ in []]
    return locals()

On #104603, calling this gives:

>>> __b()
{'__b': <function __b at 0x100e3e390>}

But on 3.11:

>>> __b()
{}

So the locals() in the outer function can now include comprehension variables from the inner comprehension. cc @carljm

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

type-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions