Message391039
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. |
|
Date |
User |
Action |
Args |
2021-04-14 07:34:28 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger |
2021-04-14 07:34:28 | serhiy.storchaka | set | messageid: <1618385668.86.0.518778578496.issue43838@roundup.psfhosted.org> |
2021-04-14 07:34:28 | serhiy.storchaka | link | issue43838 messages |
2021-04-14 07:34:28 | serhiy.storchaka | create | |
|