[issue14385] Support other types than dict for __builtins__

STINNER Victor report at bugs.python.org
Thu Apr 5 14:09:42 CEST 2012


STINNER Victor <victor.stinner at gmail.com> added the comment:

New version:
 - if __build_class__ is missing, raise a NameError instead of surprising ImportError
 - add tests
 - if PyObject_GetItem on __builtins__ or globals fail, only raise NameError if the exception is a KeyError

Before my patch, a new dict was created for builtins if __builtins__ exists in global but is not a dict. With my patch, the __builtins__ is kept and the type is checked at runtime. If __builtins__ is not a mapping, an exception is raised on lookup in ceval.c.

We may check __builtins__ type in PyFrame_New() using:

PyDict_Check(builtins) || (PyMapping_Check(mapping) && !PyList_Check(mapping) && !PyTuple_Check(mapping))

(PyDict_Check(builtins) is checked first for performance)

----------
Added file: http://bugs.python.org/file25132/builtins-2.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue14385>
_______________________________________


More information about the Python-bugs-list mailing list