The purpose of MappingProxyType is to provide a read-only proxy for mapping. It should not expose the underlying mapping because it would invalidate the purpose of read-only proxy. But there is a way to do this using comparison operator:
from types import MappingProxyType
orig = {1: 2}
proxy = MappingProxyType(orig)
class X:
def __eq__(self, other):
other[1] = 3
assert proxy[1] == 2
proxy == X()
assert proxy[1] == 3
assert orig[1] == 3
In particularly it allows to modify __dict__ of builtin types. |