Single type for __builtins__ in Py3.0

Collin Winter collinw at gmail.com
Fri Sep 23 21:33:01 CEST 2005


On 9/23/05, Christopher Subich <csubich.spamblock at subich.spam.com.block> wrote:
> How would this change, if made in a minimal way, impact the "provide
> alternate globals() and locals() to eval and exec" feature?  Altering
> __builtins__ is a half-assed way of providing some sort of security, but
> it's probably useful in preventing user-supplied code from shooting
> itself in the foot without aiming first.

In all cases (eval, exec, execfile), the globals parameter must be a
dict and the locals can be any mapping object, so the value of the
__builtins__ key would just need to be a module (could be created with
the "new" module). This is about the same breakage as with any other
code using __builtins__.

One possibility would be to deprecate the dict-form. This could be
done as Tom Anderson suggests, by supporting both __getattr__ and
__getitem__, with the latter issuing a deprecation warning for a
while. My tests indicate that this is possible, with both module.attr
and module['item'] forms available.

Collin Winter



More information about the Python-list mailing list