]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-41706: Fix special method invocation docs to mention using type() (GH-22084)
authorWilliam Chargin <wchargin@gmail.com>
Wed, 4 Aug 2021 20:43:06 +0000 (13:43 -0700)
committerGitHub <noreply@github.com>
Wed, 4 Aug 2021 20:43:06 +0000 (13:43 -0700)
Doc/reference/datamodel.rst
Misc/NEWS.d/next/Documentation/2020-09-03-13-37-19.bpo-41706._zXWOR.rst [new file with mode: 0644]

index bb0b7e059f132d6ce25c67ce815ff303160dbe56..2c76e5656b0e63718712a559e80286ef783ddb26 100644 (file)
@@ -2439,7 +2439,7 @@ left undefined.
    (``+``, ``-``, ``*``, ``@``, ``/``, ``//``, ``%``, :func:`divmod`,
    :func:`pow`, ``**``, ``<<``, ``>>``, ``&``, ``^``, ``|``).  For instance, to
    evaluate the expression ``x + y``, where *x* is an instance of a class that
-   has an :meth:`__add__` method, ``x.__add__(y)`` is called.  The
+   has an :meth:`__add__` method, ``type(x).__add__(x, y)`` is called.  The
    :meth:`__divmod__` method should be the equivalent to using
    :meth:`__floordiv__` and :meth:`__mod__`; it should not be related to
    :meth:`__truediv__`.  Note that :meth:`__pow__` should be defined to accept
@@ -2475,8 +2475,9 @@ left undefined.
    (swapped) operands.  These functions are only called if the left operand does
    not support the corresponding operation [#]_ and the operands are of different
    types. [#]_ For instance, to evaluate the expression ``x - y``, where *y* is
-   an instance of a class that has an :meth:`__rsub__` method, ``y.__rsub__(x)``
-   is called if ``x.__sub__(y)`` returns *NotImplemented*.
+   an instance of a class that has an :meth:`__rsub__` method,
+   ``type(y).__rsub__(y, x)`` is called if ``type(x).__sub__(x, y)`` returns
+   *NotImplemented*.
 
    .. index:: builtin: pow
 
diff --git a/Misc/NEWS.d/next/Documentation/2020-09-03-13-37-19.bpo-41706._zXWOR.rst b/Misc/NEWS.d/next/Documentation/2020-09-03-13-37-19.bpo-41706._zXWOR.rst
new file mode 100644 (file)
index 0000000..6406494
--- /dev/null
@@ -0,0 +1,2 @@
+Fix docs about how methods like ``__add__`` are invoked when evaluating
+operator expressions.