[Python-ideas] Revisiting Immutable Mappings

Steven D'Aprano steve at pearwood.info
Wed Oct 10 19:23:48 EDT 2018

Hi Philiip, and welcome,

On Wed, Oct 10, 2018 at 12:04:48PM -0500, Philip Martin wrote:

> I generally have used MappingProxyType as a way to set default mapping 
> to a function or to set an empty mapping to a function.

> I've created a gist with an example use case:
> https://gist.github.com/pmart123/493edf84d9aa61691ca7321325ebb6ab

Please try to keep the discussion in one place (i.e. here), for the 
benefit of the archives and for those who have email access but not 
unrestricted web access.

Can you explain (in English) your use-case, and why MappingProxyType 
isn't suitable? If it *is* suitable, how does your proposal differ?

If the only proposal is to rename types.MappingProxyType to a builtin 
"frozendict", that's one thing; if the proposal is something else, you 
should explain what.

> I've included an example of what code typically looks like when using
> MappingProxyType and what it could look like with a
> frozendict implementation.

Wouldn't that be just:

    from types import MappingProxyType as frozendict
    d = frozendict({'spam': 1, 'eggs': 2})


    d = frozendict({'spam': 1, 'eggs': 2})

Apart from the initial import, how would they be different? You want a 
frozendict; the existing MappingProxyType provides a frozendict (with a 
surprising name, but never mind...). Wouldn't you use them exactly the 
same way? They both (I presume) offer precisely the same read-only 
access to the mapping interface.


More information about the Python-ideas mailing list