[Python-Dev] PEP 416: Add a frozendict builtin type

Eric Snow ericsnowcurrently at gmail.com
Sun Mar 4 03:07:57 CET 2012


On Sat, Mar 3, 2012 at 4:11 PM, Victor Stinner <victor.stinner at gmail.com> wrote:
> Le 29/02/2012 19:21, Victor Stinner a écrit :
>>
>> Rationale
>> =========
>>
>> (...) Use cases of frozendict: (...)
>
>
> I updated the PEP to list use cases described in the other related mailing
> list thread.
> ---
> Use cases:
>
>  * frozendict lookup can be done at compile time instead of runtime because
> the mapping is read-only. frozendict can be used instead of a preprocessor
> to remove conditional code at compilation, like code specific to a debug
> build.
>  * hashable frozendict can be used as a key of a mapping or as a member of
> set. frozendict can be used to implement a cache.
>  * frozendict avoids the need of a lock when the frozendict is shared by
> multiple threads or processes, especially hashable frozendict. It would also
> help to prohibe coroutines (generators + greenlets) to modify the global
> state.
>  * frozendict helps to implement read-only object proxies for security
> modules. For example, it would be possible to use frozendict type for
> __builtins__ mapping or type.__dict__. This is possible because frozendict
> is compatible with the PyDict C API.
>  * frozendict avoids the need of a read-only proxy in some cases. frozendict
> is faster than a proxy because getting an item in a frozendict is a fast
> lookup whereas a proxy requires a function call.
>  * use a frozendict as the default value of function argument: avoid the
> problem of mutable default argument.

Is your implementation (adapted to a standalone type) something you
could put up on the cheeseshop?

-eric


More information about the Python-Dev mailing list