mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
gh-104219: Document that idunders can return NotImplemented (#104220)
Co-authored-by: C.A.M. Gerlach <CAM.Gerlach@Gerlach.CAM> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
fee86fd9a4
commit
2713c2abc8
1 changed files with 4 additions and 2 deletions
|
|
@ -3044,10 +3044,12 @@ left undefined.
|
||||||
(``+=``, ``-=``, ``*=``, ``@=``, ``/=``, ``//=``, ``%=``, ``**=``, ``<<=``,
|
(``+=``, ``-=``, ``*=``, ``@=``, ``/=``, ``//=``, ``%=``, ``**=``, ``<<=``,
|
||||||
``>>=``, ``&=``, ``^=``, ``|=``). These methods should attempt to do the
|
``>>=``, ``&=``, ``^=``, ``|=``). These methods should attempt to do the
|
||||||
operation in-place (modifying *self*) and return the result (which could be,
|
operation in-place (modifying *self*) and return the result (which could be,
|
||||||
but does not have to be, *self*). If a specific method is not defined, the
|
but does not have to be, *self*). If a specific method is not defined, or if
|
||||||
|
that method returns :data:`NotImplemented`, the
|
||||||
augmented assignment falls back to the normal methods. For instance, if *x*
|
augmented assignment falls back to the normal methods. For instance, if *x*
|
||||||
is an instance of a class with an :meth:`__iadd__` method, ``x += y`` is
|
is an instance of a class with an :meth:`__iadd__` method, ``x += y`` is
|
||||||
equivalent to ``x = x.__iadd__(y)`` . Otherwise, ``x.__add__(y)`` and
|
equivalent to ``x = x.__iadd__(y)`` . If :meth:`__iadd__` does not exist, or if ``x.__iadd__(y)``
|
||||||
|
returns :data:`!NotImplemented`, ``x.__add__(y)`` and
|
||||||
``y.__radd__(x)`` are considered, as with the evaluation of ``x + y``. In
|
``y.__radd__(x)`` are considered, as with the evaluation of ``x + y``. In
|
||||||
certain situations, augmented assignment can result in unexpected errors (see
|
certain situations, augmented assignment can result in unexpected errors (see
|
||||||
:ref:`faq-augmented-assignment-tuple-error`), but this behavior is in fact
|
:ref:`faq-augmented-assignment-tuple-error`), but this behavior is in fact
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue