Steven, that's a great idea, and I would be 100% up for your suggestion to have types.MappingProxyType renamed to frozendict. However, the differences in the behavior of MappingProxyType's constructor versus dict's would make the API's behavior confusing IMO. For example, MappingProxyType(x=5, y=10) throws a TypeError. I don't think most people would expect this.

MappingProxyType to me though does seem to be a non-obvious name compared to say frozenset as you have mentioned. Plus, it's included in a module that I would say is very low level alongside functions like prepare_class, new_class, etc.



On Wed, Oct 10, 2018 at 6:24 PM Steven D'Aprano <steve@pearwood.info> wrote:
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})

versus:

    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.



--
Steve
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/