[New-bugs-announce] [issue43838] There is a way to access an underlying mapping in MappingProxyType
Serhiy Storchaka
report at bugs.python.org
Wed Apr 14 03:34:28 EDT 2021
New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:
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.
----------
components: Interpreter Core
messages: 391039
nosy: rhettinger, serhiy.storchaka
priority: normal
severity: normal
status: open
title: There is a way to access an underlying mapping in MappingProxyType
type: behavior
versions: Python 3.10, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43838>
_______________________________________
More information about the New-bugs-announce
mailing list