[New-bugs-announce] [issue14385] Support other types than dict for __builtins__
report at bugs.python.org
Thu Mar 22 02:35:35 CET 2012
New submission from STINNER Victor <victor.stinner at gmail.com>:
CPython expects __builtins__ to be a dict, but it is interesting to be able to use another type. For example, my pysandbox project (sandbox to secure Python) requires a read-only mapping for __builtins__.
The PEP 416 was rejected, so there is no builtin frozendict type, but it looks like the dictproxy type will be exposed as a public type.
Attached patch uses PyDict_CheckExact() to check if __builtins__ is a dict and add a "slow-path" for other types. The overhead on runtime performance should be very low (near zero), PyDict_CheckExact() just dereference a pointer (to read the object type) and compare two pointers.
The patch depends on issue #14383 patch (identifier.patch) for the __build_class__ identifier. I can write a new patch without this dependency if needed.
components: Interpreter Core
title: Support other types than dict for __builtins__
versions: Python 3.3
Added file: http://bugs.python.org/file24989/builtins.patch
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce