You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Seeing that code lead to trying the following experiment:
==========
>>> from types import MappingProxyType
>>> d = {}
>>> proxy = MappingProxyType(d)
>>> classSneaky:
... def__eq__(self, other):
... if other is d:
... raiseRuntimeError("Broke encapsulation")
...
>>> proxy == Sneaky()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in __eq__
RuntimeError: Broke encapsulation
==========
The new __or__ implementation has a corresponding loophole:
========
>>> classSneakyOr:
... def__or__(self, other):
... if other is d:
... raiseRuntimeError("Broke encapsulation")
... def__ror__(self, other):
... returnself.__or__(other)
...
>>> proxy | SneakyOr()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 6, in __ror__
File "<stdin>", line 4, in __or__
RuntimeError: Broke encapsulation
========
Delegating these operations to the underlying mapping via the abstract operation layer means that the underlying mapping gets exposed to the operand coercion machinery and can hence be accessed by the other operand.
Activity
ncoghlan commentedon Jul 10, 2021
The fast locals proxy implementation for PEP-558 used the existing MappingProxyType implementation as a starting point.
This meant I noticed the following code in the mapping proxy comparison implementation:
======
======
Seeing that code lead to trying the following experiment:
==========
==========
The new
__or__implementation has a corresponding loophole:========
========
Delegating these operations to the underlying mapping via the abstract operation layer means that the underlying mapping gets exposed to the operand coercion machinery and can hence be accessed by the other operand.
serhiy-storchaka commentedon Jul 10, 2021
It is a duplicate of bpo-43838.