[Python-ideas] Expose a child factory using MappingProxyType in builtins

Michel Desmoulin desmoulinmichel at gmail.com
Tue Feb 28 07:17:49 EST 2017

We have the immutable frozenset for sets and and tuples for lists.

But we also have something to manipulate dict as immutable datastructures:

>>> from types import MappingProxyType as idict
>>> d = idict({'a':1, 'b':2, 'c':3})
>>> d['a'] = 4
Traceback (most recent call last):
  File "<ipython-input-3-c6f93d6278af>", line 1, in <module>
    d['a'] = 4
TypeError: 'mappingproxy' object does not support item assignment

We could expose this as a built type to allow the last of the most
important data structure in Python to be easily immutable.

More information about the Python-ideas mailing list