On Thu, Mar 1, 2012 at 12:35 PM, André Malo <n...@perlig.de> wrote: > * Guido van Rossum wrote: > >> On Thu, Mar 1, 2012 at 9:44 AM, Victor Stinner <victor.stin...@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.
Heh, that's a great idea. Can you file a bug for that? >> 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. I know I've done that once or twice in my life too, but it's a pretty rare use case and as you say the solution is simple enough. An alternative is frozenset(d.items()) -- someone should compare the timing of these for large dicts. -- --Guido van Rossum (python.org/~guido) _______________________________________________ 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