8000 bpo-41706: Fix special method invocation docs to mention using type()… · python/cpython@80f33f2 · GitHub
[go: up one dir, main page]

Skip to content

Commit 80f33f2

Browse files
authored
bpo-41706: Fix special method invocation docs to mention using type() (GH-22084)
1 parent a8dc489 commit 80f33f2

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Doc/reference/datamodel.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2439,7 +2439,7 @@ left undefined.
24392439
(``+``, ``-``, ``*``, ``@``, ``/``, ``//``, ``%``, :func:`divmod`,
24402440
:func:`pow`, ``**``, ``<<``, ``>>``, ``&``, ``^``, ``|``). For instance, to
24412441
evaluate the expression ``x + y``, where *x* is an instance of a class that
2442-
has an :meth:`__add__` method, ``x.__add__(y)`` is called. The
2442+
has an :meth:`__add__` method, ``type(x).__add__(x, y)`` is called. The
24432443
:meth:`__divmod__` method should be the equivalent to using
24442444
:meth:`__floordiv__` and :meth:`__mod__`; it should not be related to
24452445
:meth:`__truediv__`. Note that :meth:`__pow__` should be defined to accept
@@ -2475,8 +2475,9 @@ left undefined.
24752475
(swapped) operands. These functions are only called if the left operand does
24762476
not support the corresponding operation [#]_ and the operands are of different
24772477
types. [#]_ For instance, to evaluate the expression ``x - y``, where *y* is
2478-
an instance of a class that has an :meth:`__rsub__` method, ``y.__rsub__(x)``
2479-
is called if ``x.__sub__(y)`` returns *NotImplemented*.
2478+
an instance of a class that has an :meth:`__rsub__` method,
2479+
``type(y).__rsub__(y, x)`` is called if ``type(x).__sub__(x, y)`` returns
2480+
*NotImplemented*.
24802481

24812482
.. index:: builtin: pow
24822483

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix docs about how methods like ``__add__`` are invoked when evaluating
2+
operator expressions.

0 commit comments

Comments
 (0)
0