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

Lambda doesn't see changes of global variables #3

Open
splitline opened this issue Jul 15, 2021 · 0 comments
Open

Lambda doesn't see changes of global variables #3

splitline opened this issue Jul 15, 2021 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@splitline
Copy link
Owner

splitline commented Jul 15, 2021

The globals for lambda is just a clone/snapshot of current context.

Pickora/compiler.py

Lines 355 to 358 in 7e0e8eb

func_globals = ast.Dict(keys=[], values=[])
for name in code_args[8]: # co_names
func_globals.keys.append(ast.Constant(value=name))
func_globals.values.append(ast.Name(id=name))

So if any global variables are changed after the lambda definition, the lambda won't see those changes
For example:

val = 'before'
f = lambda:val
val = 'after'
print(f())  # before

I am not sure if there are any way to fix this 🤔

@splitline splitline added the bug Something isn't working label Jul 15, 2021
@splitline splitline self-assigned this Jul 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant