[issue14385] Support other types than dict for __builtins__
STINNER Victor
report at bugs.python.org
Mon Mar 26 01:59:41 CEST 2012
STINNER Victor <victor.stinner at gmail.com> added the comment:
With my patch, Python doesn't check __builtins__ type whereas ceval.c replaces any lookup error by a NameError. Example:
$ ./python
Python 3.3.0a1+ (default:f8d01c8baf6a+, Mar 26 2012, 01:44:48)
>>> code=compile("print('Hello World!')", "", "exec")
>>> exec(code,{'__builtins__': {'print': print}})
Hello World!
>>> exec(code,{'__builtins__': {}})
NameError: name 'print' is not defined
>>> exec(code,{'__builtins__': 1})
NameError: name 'print' is not defined
It should only replace the current exception by NameError if the current exception is a LookupError.
And my patch on LOAD_GLOBAL is not correct, it does still call PyDict_GetItem. I'm waiting until #14383 is done before writing a new patch.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14385>
_______________________________________
More information about the Python-bugs-list
mailing list