[Python-ideas] Revisiting Immutable Mappings

Cameron Simpson cs at cskk.id.au
Wed Oct 10 22:01:29 EDT 2018

On 10Oct2018 20:25, Philip Martin <philip.martin2007 at gmail.com> wrote:
>Steven, that's a great idea, and I would be 100% up for your suggestion to
>have types.MappingProxyType renamed to frozendict.

I'm not for the rename, myself. Though I'd not be against a frozendict 
factory in builtins, a tiny shim for MappingProxyType.

>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.

Well, if it were called frozendict, indeed not. It should act like dict.


  def frozendict(**kw):
      return MappingProxyType(kw)

You could make an argument for that (or a slightly heftier version 
accepting the various things dict accepts). Or... you could just keep 
such a thing in your personal kit as a trivial way to spell 
"frozendict". One could argue for the above as a nice example to live in 
the docs perhaps.

But not everything needs a special name.

Cameron Simpson <cs at cskk.id.au>

More information about the Python-ideas mailing list