add __builtins__ to globals in py.run() if they're missing#3378
add __builtins__ to globals in py.run() if they're missing#3378davidhewitt merged 1 commit intoPyO3:mainfrom
__builtins__ to globals in py.run() if they're missing#3378Conversation
f3e1a67 to
1ebcb0a
Compare
davidhewitt
left a comment
There was a problem hiding this comment.
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. |
I think that’s more confusing than the current option (especially given possibility of code like |
davidhewitt
left a comment
There was a problem hiding this comment.
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. |
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