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

gh-104619: never leak comprehension locals to outer locals() #104637

Merged
merged 1 commit into from May 19, 2023

Conversation

carljm
Copy link
Contributor

@carljm carljm commented May 19, 2023

The initial implementation of PEP 709 didn't bother to clear comprehension locals after an inlined comprehension, if the name was a global outside the comprehension. This was purely an optimization to save a couple extra instructions in this case; it didn't seem necessary to clear the comprehension value, since outer references to the name would use LOAD_GLOBAL anyway and not see the value in fastlocals.

But it is necessary to clear the comprehension local even in this case, because otherwise it will still show up in locals(), or in debugger usage, outside of the comprehension.

@JelleZijlstra JelleZijlstra merged commit 70c7796 into python:main May 19, 2023
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

PEP 709: Comprehension iteration variable leaks into outer locals()
3 participants