A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2012-March/117197.html below:

[Python-Dev] Add a frozendict builtin type

[Python-Dev] Add a frozendict builtin typeGuido van Rossum guido at python.org
Fri Mar 2 00:11:35 CET 2012
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)
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4