(original) (raw)

changeset: 89541:61ceb299a255 parent: 89539:a140caad76bc parent: 89540:f9cb5a44879c user: R David Murray rdmurray@bitdance.com date: Sun Mar 09 18:51:35 2014 -0400 files: Doc/faq/programming.rst Doc/reference/datamodel.rst description: Merge #19953: Clarify the wording of the augmented assignment discussion. diff -r a140caad76bc -r 61ceb299a255 Doc/faq/programming.rst --- a/Doc/faq/programming.rst Sun Mar 09 18:09:51 2014 -0400 +++ b/Doc/faq/programming.rst Sun Mar 09 18:51:35 2014 -0400 @@ -1103,6 +1103,7 @@ 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? --------------------------------------------------------------------------- diff -r a140caad76bc -r 61ceb299a255 Doc/reference/datamodel.rst --- a/Doc/reference/datamodel.rst Sun Mar 09 18:09:51 2014 -0400 +++ b/Doc/reference/datamodel.rst Sun Mar 09 18:51:35 2014 -0400 @@ -2050,11 +2050,13 @@ ``&=``, ``^=``, ``|=``). These methods should attempt to do the 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 augmented - assignment falls back to the normal methods. For instance, to execute the - statement ``x += y``, where *x* is an instance of a class that has an - :meth:`__iadd__` method, ``x.__iadd__(y)`` is called. If *x* is an instance - of a class that does not define a :meth:`__iadd__` method, ``x.__add__(y)`` - and ``y.__radd__(x)`` are considered, as with the evaluation of ``x + y``. + 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 equivalent + to ``x = x.__iadd__(y)`` . Otherwise, ``x.__add__(y)`` and ``y.__radd__(x)`` + are considered, as with the evaluation of ``x + y``. In certain situations, + 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) /rdmurray@bitdance.com