summaryrefslogtreecommitdiffstats
path: root/Doc/faq
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2013-05-21 15:45:09 (GMT)
committerR David Murray <rdmurray@bitdance.com>2013-05-21 15:45:09 (GMT)
commitb3a579223ea0d7d9354a0960751591f0d982e87a (patch)
tree0f4520e5cd0748d67491897ea1c6979fca2712b2 /Doc/faq
parent3ee6dabf5b2bcfe5aa27a6db4f7adb7d7f33f8d6 (diff)
parent95ae99205e3a9da45b958415af92432ca990914e (diff)
downloadcpython-b3a579223ea0d7d9354a0960751591f0d982e87a.zip
cpython-b3a579223ea0d7d9354a0960751591f0d982e87a.tar.gz
cpython-b3a579223ea0d7d9354a0960751591f0d982e87a.tar.bz2
merge #17973: fix technical inaccuracy in faq entry (it now passes doctest).
Diffstat (limited to 'Doc/faq')
-rw-r--r--Doc/faq/programming.rst13
1 files changed, 8 insertions, 5 deletions
diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
index 7713450..6a720d1 100644
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -1131,7 +1131,7 @@ a tuple points to.
Under the covers, what this augmented assignment statement is doing is
approximately this::
- >>> result = a_tuple[0].__iadd__(1)
+ >>> result = a_tuple[0] + 1
>>> a_tuple[0] = result
Traceback (most recent call last):
...
@@ -1154,16 +1154,19 @@ that even though there was an error, the append worked::
>>> a_tuple[0]
['foo', 'item']
-To see why this happens, you need to know that for lists, ``__iadd__`` is equivalent
-to calling ``extend`` on the list and returning the list. That's why we say
-that for lists, ``+=`` is a "shorthand" for ``list.extend``::
+To see why this happens, you need to know that (a) if an object implements an
+``__iadd__`` magic method, it gets called when the ``+=`` augmented assignment
+is executed, and its return value is what gets used in the assignment statement;
+and (b) for lists, ``__iadd__`` is equivalent to calling ``extend`` on the list
+and returning the list. That's why we say that for lists, ``+=`` is a
+"shorthand" for ``list.extend``::
>>> a_list = []
>>> a_list += [1]
>>> a_list
[1]
-is equivalent to::
+This is equivalent to::
>>> result = a_list.__iadd__([1])
>>> a_list = result