This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients rhettinger, serhiy.storchaka
Date 2021-04-14.07:34:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1618385668.86.0.518778578496.issue43838@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2021-04-14 07:34:28serhiy.storchakasetrecipients: + serhiy.storchaka, rhettinger
2021-04-14 07:34:28serhiy.storchakasetmessageid: <1618385668.86.0.518778578496.issue43838@roundup.psfhosted.org>
2021-04-14 07:34:28serhiy.storchakalinkissue43838 messages
2021-04-14 07:34:28serhiy.storchakacreate