Skip to content

Commit 21a9536

Browse files
[3.12] doc: Mention the missing reflected special methods for all binary operations (GH-119931) (#120064)
doc: Mention the missing reflected special methods for all binary operations (GH-119931) (cherry picked from commit bf5e106) Co-authored-by: Paulo Freitas <[email protected]>
1 parent 5c06b34 commit 21a9536

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

Doc/reference/expressions.rst

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,7 +1204,8 @@ Raising ``0.0`` to a negative power results in a :exc:`ZeroDivisionError`.
12041204
Raising a negative number to a fractional power results in a :class:`complex`
12051205
number. (In earlier versions it raised a :exc:`ValueError`.)
12061206

1207-
This operation can be customized using the special :meth:`~object.__pow__` method.
1207+
This operation can be customized using the special :meth:`~object.__pow__` and
1208+
:meth:`~object.__rpow__` methods.
12081209

12091210
.. _unary:
12101211

@@ -1292,6 +1293,9 @@ This operation can be customized using the special :meth:`~object.__mul__` and
12921293
The ``@`` (at) operator is intended to be used for matrix multiplication. No
12931294
builtin Python types implement this operator.
12941295

1296+
This operation can be customized using the special :meth:`~object.__matmul__` and
1297+
:meth:`~object.__rmatmul__` methods.
1298+
12951299
.. versionadded:: 3.5
12961300

12971301
.. index::
@@ -1307,8 +1311,10 @@ integer; the result is that of mathematical division with the 'floor' function
13071311
applied to the result. Division by zero raises the :exc:`ZeroDivisionError`
13081312
exception.
13091313

1310-
This operation can be customized using the special :meth:`~object.__truediv__` and
1311-
:meth:`~object.__floordiv__` methods.
1314+
The division operation can be customized using the special :meth:`~object.__truediv__`
1315+
and :meth:`~object.__rtruediv__` methods.
1316+
The floor division operation can be customized using the special
1317+
:meth:`~object.__floordiv__` and :meth:`~object.__rfloordiv__` methods.
13121318

13131319
.. index::
13141320
single: modulo
@@ -1333,7 +1339,8 @@ also overloaded by string objects to perform old-style string formatting (also
13331339
known as interpolation). The syntax for string formatting is described in the
13341340
Python Library Reference, section :ref:`old-string-formatting`.
13351341

1336-
The *modulo* operation can be customized using the special :meth:`~object.__mod__` method.
1342+
The *modulo* operation can be customized using the special :meth:`~object.__mod__`
1343+
and :meth:`~object.__rmod__` methods.
13371344

13381345
The floor division operator, the modulo operator, and the :func:`divmod`
13391346
function are not defined for complex numbers. Instead, convert to a floating
@@ -1360,7 +1367,8 @@ This operation can be customized using the special :meth:`~object.__add__` and
13601367
The ``-`` (subtraction) operator yields the difference of its arguments. The
13611368
numeric arguments are first converted to a common type.
13621369

1363-
This operation can be customized using the special :meth:`~object.__sub__` method.
1370+
This operation can be customized using the special :meth:`~object.__sub__` and
1371+
:meth:`~object.__rsub__` methods.
13641372

13651373

13661374
.. _shifting:
@@ -1381,8 +1389,10 @@ The shifting operations have lower priority than the arithmetic operations:
13811389
These operators accept integers as arguments. They shift the first argument to
13821390
the left or right by the number of bits given by the second argument.
13831391

1384-
This operation can be customized using the special :meth:`~object.__lshift__` and
1385-
:meth:`~object.__rshift__` methods.
1392+
The left shift operation can be customized using the special :meth:`~object.__lshift__`
1393+
and :meth:`~object.__rlshift__` methods.
1394+
The right shift operation can be customized using the special :meth:`~object.__rshift__`
1395+
and :meth:`~object.__rrshift__` methods.
13861396

13871397
.. index:: pair: exception; ValueError
13881398

0 commit comments

Comments
 (0)