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

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to