gh-121377: Fix closure with intervening comprehension - #124696
Conversation
|
Found this failure case: |
|
Simpler repro: |
| code = """ | ||
| x = 1 | ||
| def f(): | ||
| [lambda: x for x in [1]] |
There was a problem hiding this comment.
| [lambda: x for x in [1]] | |
| [lambda: x for x in [2]] |
As discussed:
- Use a different value (the test ran correctly but used the wrong
1) - Should change it to execute the lambda so we ensure the value of
xinside the lambda is right
|
@carljm I think the tests are not testing the exact situation in my original example. They already pass in Python 3.13. The intervening list comprehension needs to be in the innermost scope like my original example, which still fails. |
|
oh, sorry ignore me, I was confused. apparently the tests passed because I ran it at module scope. they are also tested in function scope, so that is ok, I think |
|
but maybe you should also add a test to also test a local in f() to be sure. (I keep getting confused by the change of the function names between our examples) |
|
This PR is stale because it has been open for 30 days with no activity. |
Fix the case where a comprehension iteration variable is inlined into a function that otherwise does not have a variable by that name, but the name should be a free variable from an enclosing scope passed through to other enclosed scopes.