summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2014-03-09 22:51:16 (GMT)
committerR David Murray <rdmurray@bitdance.com>2014-03-09 22:51:16 (GMT)
commit14d7b718bacb6b8a0702489d04895ea4e4b11131 (patch)
tree65db0504530f77bc40e62a45e122cd7f2b078381 /Doc
parent6120739f0cb1c26069570fea701fe79489f1cd9d (diff)
downloadcpython-14d7b718bacb6b8a0702489d04895ea4e4b11131.zip
cpython-14d7b718bacb6b8a0702489d04895ea4e4b11131.tar.gz
cpython-14d7b718bacb6b8a0702489d04895ea4e4b11131.tar.bz2
#19953: Clarify the wording of the augmented assignment discussion.
Patch by Priya Pappachan, based on suggestions from Terry Reedy and myself.
Diffstat (limited to 'Doc')
-rw-r--r--Doc/faq/programming.rst1
-rw-r--r--Doc/reference/datamodel.rst12
2 files changed, 8 insertions, 5 deletions
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index 42e55d6..280d5e1 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -1103,6 +1103,7 @@ Use a list comprehension::
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 --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst
index 22cac07..160af30 100644
--- a/Doc/reference/datamodel.rst
+++ b/Doc/reference/datamodel.rst
@@ -2023,11 +2023,13 @@ left undefined.
``&=``, ``^=``, ``|=``). 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)