Skip to content

fix: pp.deep resolves free vars inside nested function scopes#78

Open
SAY-5 wants to merge 1 commit into
alexmojaki:masterfrom
SAY-5:fix-pp-deep-free-var-in-genexpr
Open

fix: pp.deep resolves free vars inside nested function scopes#78
SAY-5 wants to merge 1 commit into
alexmojaki:masterfrom
SAY-5:fix-pp-deep-free-var-in-genexpr

Conversation

@SAY-5

@SAY-5 SAY-5 commented May 13, 2026

Copy link
Copy Markdown

pp.deep compiles and evaluates the expression with eval(code, frame.f_globals, frame.f_locals), but generator expressions, comprehensions, and nested lambdas inside the expression run in their own function scope where the eval frame's locals are not visible, so any reference to an enclosing-function variable raises NameError (reported as !!! NameError! in the output and re-raised, issue #75). This merges f_locals into the globals dict passed to eval so those names resolve via the eval frame's globals from any nested scope, and stops mutating the caller's f_globals for the wrapper hooks.

Closes #75

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pp.deep: 'NameError: arg' in generator expression

1 participant