[Python-Dev] Add a frozendict builtin type
Guido van Rossum
guido at python.org
Fri Mar 2 00:11:35 CET 2012
More information about the Python-Dev mailing list
Fri Mar 2 00:11:35 CET 2012
- Previous message: [Python-Dev] Add a frozendict builtin type
- Next message: [Python-Dev] Add a frozendict builtin type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Thu, Mar 1, 2012 at 12:35 PM, André Malo <nd at perlig.de> wrote: > * Guido van Rossum wrote: > >> 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. 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)
- Previous message: [Python-Dev] Add a frozendict builtin type
- Next message: [Python-Dev] Add a frozendict builtin type
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-Dev mailing list