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

Wrong binding of closure variable with intervening list comprehension #121377

Open
limwz01 opened this issue Jul 4, 2024 · 4 comments
Open

Wrong binding of closure variable with intervening list comprehension #121377

limwz01 opened this issue Jul 4, 2024 · 4 comments
Assignees
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error

Comments

@limwz01
Copy link

limwz01 commented Jul 4, 2024

Bug report

Bug description:

def f(x):
    def g():
        print([x for x in range(10)])
        def h():
            print(x)
        return h
    print(x)
    return g
f(1)()()

The above had always bound x in h to the parameter of f. But it no longer works and somehow binds to a local in g, throwing the following error:

NameError: cannot access free variable 'x' where it is not associated with a value in enclosing scope

CPython versions tested on:

3.12

Operating systems tested on:

Linux, Windows

Linked PRs

@limwz01 limwz01 added the type-bug An unexpected behavior, bug, or error label Jul 4, 2024
@gaogaotiantian
Copy link
Member

This is probably related to PEP 709 @carljm .

@eryksun eryksun added 3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes labels Jul 4, 2024
@carljm carljm self-assigned this Jul 5, 2024
@carljm
Copy link
Member

carljm commented Jul 5, 2024

I've just moved house and am behind on everything, so it may be a bit before I can get to this, but I will fix it.

@limwz01
Copy link
Author

limwz01 commented Aug 27, 2024

@carljm any updates?

@carljm
Copy link
Member

carljm commented Aug 27, 2024

I'm intending to work on this during the upcoming core dev sprint in September. If someone else gets to it first that's fine, though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

4 participants