Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
JelleZijlstra opened this issue May 18, 2023 · 0 comments · Fixed by #104637
Closed

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

JelleZijlstra opened this issue May 18, 2023 · 0 comments · Fixed by #104637
Assignees
Labels
type-bug An unexpected behavior, bug, or error

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented May 18, 2023

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

@JelleZijlstra JelleZijlstra added the type-bug An unexpected behavior, bug, or error label May 18, 2023
@JelleZijlstra JelleZijlstra changed the title PEP 709: PEP 709: Comprehension iteration variable leaks into outer locals() May 18, 2023
@carljm carljm self-assigned this May 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants