-
-
Notifications
You must be signed in to change notification settings - Fork 776
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document weird behavior of runPython locals parameter #4673
Comments
Thanks for the report @ytetsuro! We use the The An interesting behavior of eval() is that, unlike Python's nested function scope, eval()'s local scope does not have access to variables defined in the parent scope. So, the function The following code is a minimal reproducer that raises the same error in native Python: code = compile('''
def a(s):
c(s)
def c(s):
print(s)
a('hello world')
''', '<string>', 'exec')
eval(code, None, {}) Anyway, I agree that this is counterintuitive, and we probably need to think of a workaround. |
I resisted adding a The following prints "hi": class A:
def a():
print("hi")
a() whereas this throws class A:
def a():
print("hi")
def b():
a()
b() This second example is equivalent to your code. |
Y |
Thanks, Response! I see that it is the proper behavior! Thanks for letting me know! |
Even for people familiar with Python, this is pretty weird. We should consider adding a warning about it in the docs... |
I think I'll reopen this and label it as a documentation issue, |
馃悰 Bug
The error occurs when you try to call other functions added to the global scope in a function.
To Reproduce
code example
Error
Expected behavior
output
a
.Environment
Additional context
The text was updated successfully, but these errors were encountered: