Skip to content

bpo-41584: clarify when the reflected method of a binary arithemtic operator is called #22505

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions Doc/reference/datamodel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2376,10 +2376,11 @@ left undefined.

.. note::

If the right operand's type is a subclass of the left operand's type and that
subclass provides the reflected method for the operation, this method will be
called before the left operand's non-reflected method. This behavior allows
subclasses to override their ancestors' operations.
If the right operand's type is a subclass of the left operand's type and
that subclass provides a different implementation of the reflected method
for the operation, this method will be called before the left operand's
non-reflected method. This behavior allows subclasses to override their
ancestors' operations.


.. method:: object.__iadd__(self, other)
Expand Down Expand Up @@ -2771,6 +2772,6 @@ An example of an asynchronous context manager class::
method—that will instead have the opposite effect of explicitly
*blocking* such fallback.

.. [#] For operands of the same type, it is assumed that if the non-reflected method
(such as :meth:`__add__`) fails the operation is not supported, which is why the
reflected method is not called.
.. [#] For operands of the same type, it is assumed that if the non-reflected
method -- such as :meth:`__add__` -- fails then the overall operation is not
supported, which is why the reflected method is not called.