STINNER Victor <victor.stin...@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 <rep...@bugs.python.org>
<http://bugs.python.org/issue14385>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to