#19953: Clarify the wording of the augmented assignment discussion.

Patch by Priya Pappachan, based on suggestions from Terry Reedy
and myself.
This commit is contained in:
R David Murray 2014-03-09 18:51:16 -04:00
parent 6120739f0c
commit 14d7b718ba
2 changed files with 8 additions and 5 deletions

View file

@ -1103,6 +1103,7 @@ Use a list comprehension::
result = [obj.method() for obj in mylist] result = [obj.method() for obj in mylist]
.. _faq-augmented-assignment-tuple-error:
Why does a_tuple[i] += ['item'] raise an exception when the addition works? Why does a_tuple[i] += ['item'] raise an exception when the addition works?
--------------------------------------------------------------------------- ---------------------------------------------------------------------------

View file

@ -2023,11 +2023,13 @@ left undefined.
``&=``, ``^=``, ``|=``). These methods should attempt to do the operation ``&=``, ``^=``, ``|=``). These methods should attempt to do the operation
in-place (modifying *self*) and return the result (which could be, but does 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 augmented not have to be, *self*). If a specific method is not defined, the augmented
assignment falls back to the normal methods. For instance, to execute the assignment falls back to the normal methods. For instance, if *x* is an
statement ``x += y``, where *x* is an instance of a class that has an instance of a class with an :meth:`__iadd__` method, ``x += y`` is equivalent
:meth:`__iadd__` method, ``x.__iadd__(y)`` is called. If *x* is an instance to ``x = x.__iadd__(y)`` . Otherwise, ``x.__add__(y)`` and ``y.__radd__(x)``
of a class that does not define a :meth:`__iadd__` method, ``x.__add__(y)`` are considered, as with the evaluation of ``x + y``. In certain situations,
and ``y.__radd__(x)`` are considered, as with the evaluation of ``x + y``. augmented assignment can result in unexpected errors (see
:ref:`faq-augmented-assignment-tuple-error`), but this behavior is in
fact part of the data model.
.. method:: object.__neg__(self) .. method:: object.__neg__(self)