-
Notifications
You must be signed in to change notification settings - Fork 802
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
add __builtins__
to globals in py.run()
if they're missing
#3378
Conversation
f3e1a67
to
1ebcb0a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Many thanks, implementation looks great. My only thought: after evaluation should we attempt to remove __builtins__
from the globals
dictionary if we added it?
// `PyDict_SetItem` doesn't take ownership of `builtins`, but `PyEval_GetBuiltins` | ||
// seems to return a borrowed reference, so no leak here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
I think that’s more confusing than the current option (especially given possibility of code like |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, in which case I think let's just document that globals
will be modified in this way (on both Python::run
and Python::eval
) and call it a day.
Python code doesn't like to run without `__builtins__`, so adding them if missing seems to be a good idea. Also that's what CPython >3.10 does. See python/cpython#24564 Resolves PyO3#3370
1ebcb0a
to
0be94a5
Compare
Fixed the docs. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again!
Python code doesn't like to run without
__builtins__
, so adding them if missing seems to be a good idea. Also that's what CPython >3.10 does.See python/cpython#24564
Resolves #3370