exec ignores custom `__builtins__` in globals
Created originally on Bitbucket by icemac (Michael Howitz)
Given the following code:
code = compile('import os', '<string>', 'exec')
glb = {'__builtins__': {'__import__': lambda *a: 42}}
exec(code, glb)
print(glb['os'])
PyPy behaves differently from CPython:
- Python 2.7.13 prints
42
- Python 3.6.2 prints
42
- PyPy 5.8.0 prints
<module 'os' from '/opt/local/lib/pypy/lib-python/2.7/os.py'>
- PyPy3 5.5.0 prints
<module 'os' from '/Users/mac/python/pypy3-v5.5.0-osx64/lib-python/3/os.py'>
This prevents using a custom __import__
function.