[Python-Dev] PEP 416: Add a frozendict builtin type
Jim J. Jewett
jimjjewett at gmail.com
Thu Mar 1 05:33:21 CET 2012
More information about the Python-Dev mailing list
Thu Mar 1 05:33:21 CET 2012
- Previous message: [Python-Dev] State of PEP-3118 (memoryview part)
- Next message: [Python-Dev] PEP 416: Add a frozendict builtin type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Previous message: [Python-Dev] State of PEP-3118 (memoryview part)
- Next message: [Python-Dev] PEP 416: Add a frozendict builtin type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list