[Python-Dev] PEP 416: Add a frozendict builtin type

Jim J. Jewett jimjjewett at gmail.com
Thu Mar 1 05:33:21 CET 2012


In http://mail.python.org/pipermail/python-dev/2012-February/117113.html
Victor Stinner posted:
> An immutable mapping can be implemented using frozendict::

> class immutabledict(frozendict):
> def __new__(cls, *args, **kw):
> # ensure that all values are immutable
> for key, value in itertools.chain(args, kw.items()):
> if not isinstance(value, (int, float, complex, str, bytes)):
> hash(value)
> # frozendict ensures that all keys are immutable
> return frozendict.__new__(cls, *args, **kw)

What is the purpose of this? Is it just a hashable frozendict?
If it is for security (as some other messages suggest), then I don't
think it really helps.
 class Proxy:
 def __eq__(self, other): return self.value == other
 def __hash__(self): return hash(self.value)
An instance of Proxy is hashable, and the hash is not object.hash,
but it is still mutable. You're welcome to call that buggy, but a
secure sandbox will have to deal with much worse.
-jJ
-- 
If there are still threading problems with my replies, please 
email me with details, so that I can try to resolve them. -jJ


More information about the Python-Dev mailing list

AltStyle によって変換されたページ (->オリジナル) /