diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-06-08 12:44:30 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-06-08 12:44:30 (GMT) |
commit | 7d7a11b5d700c54260c517d0fb57fe1caf591e31 (patch) | |
tree | d902a4b2a6914307cec03db35d8d98fa05be1036 /Doc/reference | |
parent | 84f387d420fd908973cf9660f91b448d7e848b42 (diff) | |
download | cpython-7d7a11b5d700c54260c517d0fb57fe1caf591e31.zip cpython-7d7a11b5d700c54260c517d0fb57fe1caf591e31.tar.gz cpython-7d7a11b5d700c54260c517d0fb57fe1caf591e31.tar.bz2 |
Issue #23275: Backport target list assignment documentation fixes
Diffstat (limited to 'Doc/reference')
-rw-r--r-- | Doc/reference/simple_stmts.rst | 29 |
1 files changed, 14 insertions, 15 deletions
diff --git a/Doc/reference/simple_stmts.rst b/Doc/reference/simple_stmts.rst index ff5b1ca..7d71752 100644 --- a/Doc/reference/simple_stmts.rst +++ b/Doc/reference/simple_stmts.rst @@ -85,7 +85,7 @@ attributes or items of mutable objects: target_list: `target` ("," `target`)* [","] target: `identifier` : | "(" `target_list` ")" - : | "[" `target_list` "]" + : | "[" [`target_list`] "]" : | `attributeref` : | `subscription` : | `slicing` @@ -115,21 +115,25 @@ given with the definition of the object types (see section :ref:`types`). Assignment of an object to a target list, optionally enclosed in parentheses or square brackets, is recursively defined as follows. -* If the target list is a single target: The object is assigned to that target. +* If the target list is empty: The object must also be an empty iterable. -* If the target list is a comma-separated list of targets: The object must be an - iterable with the same number of items as there are targets in the target list, - and the items are assigned, from left to right, to the corresponding targets. +* If the target list is a single target in parentheses: The object is assigned + to that target. + +* If the target list is a comma-separated list of targets, or a single target + in square brackets: The object must be an iterable with the same number of + items as there are targets in the target list, and the items are assigned, + from left to right, to the corresponding targets. * If the target list contains one target prefixed with an asterisk, called a - "starred" target: The object must be a sequence with at least as many items + "starred" target: The object must be an iterable with at least as many items as there are targets in the target list, minus one. The first items of the - sequence are assigned, from left to right, to the targets before the starred - target. The final items of the sequence are assigned to the targets after - the starred target. A list of the remaining items in the sequence is then + iterable are assigned, from left to right, to the targets before the starred + target. The final items of the iterable are assigned to the targets after + the starred target. A list of the remaining items in the iterable is then assigned to the starred target (the list can be empty). - * Else: The object must be a sequence with the same number of items as there + * Else: The object must be an iterable with the same number of items as there are targets in the target list, and the items are assigned, from left to right, to the corresponding targets. @@ -150,11 +154,6 @@ Assignment of an object to a single target is recursively defined as follows. count for the object previously bound to the name to reach zero, causing the object to be deallocated and its destructor (if it has one) to be called. -* If the target is a target list enclosed in parentheses or in square brackets: - The object must be an iterable with the same number of items as there are - targets in the target list, and its items are assigned, from left to right, - to the corresponding targets. - .. index:: pair: attribute; assignment * If the target is an attribute reference: The primary expression in the |