[Python-checkins] cpython (merge 3.3 -> default): merge #17973: fix technical inaccuracy in faq entry (it now passes doctest).

r.david.murray python-checkins at python.org
Tue May 21 17:48:02 CEST 2013


http://hg.python.org/cpython/rev/26588b6a39d9
changeset:   83883:26588b6a39d9
parent:      83881:56f25569ba86
parent:      83882:6ab88d6527f1
user:        R David Murray <rdmurray at bitdance.com>
date:        Tue May 21 11:45:09 2013 -0400
summary:
  merge #17973: fix technical inaccuracy in faq entry (it now passes doctest).

files:
  Doc/faq/programming.rst |  13 ++++++++-----
  1 files changed, 8 insertions(+), 5 deletions(-)


diff --git a/Doc/faq/programming.rst b/Doc/faq/programming.rst
--- a/Doc/faq/programming.rst
+++ b/Doc/faq/programming.rst
@@ -1131,7 +1131,7 @@
 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 @@
     >>> 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

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list