Nick Coghlan <ncogh...@gmail.com> added the comment:

Delegating operations to the underlying mapping is still OK, all we're wanting 
to bypass is the operand coercion dances in abstract.c and object.c that may 
expose the underlying mapping to the *other* operand.

We don't want to implicitly copy though, as the performance hit can be 
non-trivial for large mappings, even if the algorithmic complexity doesn't 
change.

For the `nb_or` slot, it should be correct to retrieve and call `__or__` from 
the underlying mapping when the left operand is a MappingProxy instance, and 
`__ror__` when the right operand is a MappingProxy instance (but the left 
operand is not).

Rich comparison is messier though, since PyObject_RichCompare handles both the 
operand coercion dance *and* the mapping of the specific comparison operations 
to their implementation slots.

I don't see a clean solution to that other than defining a new 
PyObject_DelegateRichCompare helper function for the mapping proxy to use that 
provides the mapping from specific operands to their implementation slots 
*without* doing the coercion dance.

However we resolve it, I think it probably won't be worth the risk of 
backporting the change (this has been the way it currently is for a long time, 
and it's a "reduce the risk of error" feature rather than any kind of security 
boundary).

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43838>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to