[Python-Dev] Add a frozendict builtin type (original) (raw)

André Malo nd at perlig.de
Thu Mar 1 21:35:07 CET 2012


On Thu, Mar 1, 2012 at 9:44 AM, Victor Stinner <victor.stinner at gmail.com> wrote: > frozendict would help pysandbox but also any security Python module, > not security, but also (many) other use cases ;-)

Well, let's focus on the other use cases, because to me the sandbox use case is too controversial (never mind how confident you are :-). I like thinking through the cache use case a bit more, since this is a common pattern. But I think it would be sufficient there to prevent accidental modification, so it should be sufficient to have a dict subclass that overrides the various mutating methods: setitem, delitem, pop(), popitem(), clear(), setdefault(), update().

For the caching part, simply making the dictproxy type public would already help a lot.

What other use cases are there?

dicts as keys or as set members. I do run into this from time to time and always get tuple(sorted(items()) or something like that.

nd

s s^saaaaaoaaaoaaaaooooaaoaaaomaaaa a alataa aaoat a a a maoaa a laoata a oia a o a m a o alaoooat aaool aaoaa matooololaaatoto aaa o a o ms;s;\s;s;g;y;s;:;s;y#mailto: # \51/\134\137| http://www.perlig.de #;print;# > nd at perlig.de



More information about the Python-Dev mailing list