-
-
Notifications
You must be signed in to change notification settings - Fork 32k
locals are not passed to inner function defined in exec() #92681
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
Comments
Did the investigation with the code below, looks like the code executed by exec() inherits locals and globals from its caller method. The inner method can inherit globals further, but cannot inherit locals.
|
I think this behavior is explained by the docs in the following sentence:
The behavior you notice is consistent with that: class Somthing:
a = "hello"
def inner():
print(a)
inner()
# result: NameError: name 'a' is not defined |
It looks like that language was added in commit 83efd6c for issue #57766 @terryjreedy, do you think this needs further clarification in the docs? I could see how this text at the top of the paragraph could be misleading:
|
Closing as a duplicate of #68988. |
Bug report
A clear and concise description of what the bug is.
Include a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible.
With following code, f1 is OK, but f2 failed with the error "name 'a' is not defined"
Your environment
CPython versions tested on:
Python 3.5.2 (default, Aug 10 2017, 23:51:58)
[GCC 4.4.3] on linux
Operating system and architecture:
Linux 3.10.0-1160.25.1.el7.x86_64
The text was updated successfully, but these errors were encountered: