[Python-Dev] Add a frozendict builtin type
Mark Shannon
mark at hotpy.org
Tue Feb 28 10:47:59 CET 2012
Victor Stinner wrote:
>>> The blacklist implementation has a major issue: it is still possible
>>> to call write methods of the dict class (e.g. dict.set(my_frozendict,
>>> key, value)).
>> It is also possible to use ctypes and violate even more invariants.
>> For most purposes, this falls under "consenting adults".
>
> My primary usage of frozendict would be pysandbox, a security module.
> Attackers are not consenting adults :-)
>
> Read-only dict would also help optimization, in the CPython peephole
> or the PyPy JIT.
Not w.r.t. PyPy. It wouldn't do any harm though.
One use of frozendict that you haven't mentioned so far
is communication between concurrent processes/tasks.
These need to be able to copy objects without changing reference
semantics, which demands immutability.
Cheers,
Mark.
More information about the Python-Dev
mailing list