Issue33878
Created on 2018-06-16 13:01 by mdk, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 7762 | merged | mdk, 2018-06-17 10:47 | |
| PR 10444 | closed | pablogsal, 2018-11-10 04:15 | |
| PR 10472 | merged | miss-islington, 2018-11-11 23:59 | |
| PR 10473 | merged | miss-islington, 2018-11-11 23:59 | |
| Messages (9) | |||
|---|---|---|---|
| msg319735 - (view) | Author: Julien Palard (mdk) * ![]() |
Date: 2018-06-16 13:01 | |
In [1] I read: > If the target list is a comma-separated list of targets, or a single target in square brackets This come from https://bugs.python.org/issue23275 (patch is [2]). I suspect there's a missing case "list of targets in square brackets" (and to be pedantic "list of targets in parenthesis"). The specialized documentation about single-valued targets in sequence-like construction come from this difference: >>> (a) = 42 >>> a 42 >>> [a] = [42] >>> a 42 which is correctly described the line before: > If the target list is a single target in parentheses: The object is assigned to that target. So the correct way to state it may be: > 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. The `Else`, coupled with the existing "Assignment of an object to a target list, optionally enclosed in parentheses or square brackets" covers properly the cases: - Multiple target separated by comas (already covered) - Multiple target enclosed by parenthesis and brackets (not covered) - Single target enclosed by angle brackets (already covered) [1]: https://docs.python.org/3.7/reference/simple_stmts.html#assignment-statements [2]: https://bugs.python.org/file42878/issue23275_v4.diff |
|||
| msg319737 - (view) | Author: Martin Panter (martin.panter) * ![]() |
Date: 2018-06-16 13:32 | |
I think I intended the third option to include all comma-separated lists, including:
a, b, c = x # No brackets
(a, b, c) = x # Round brackets
[a, b, c] = x # Square brackets
a, = x # Single target with comma
Perhaps something like this would be clearer:
* If the target list is
* a comma-separated list of targets, with or without brackets, or
* a single target with a trailing comma, with or without brackets, or
* a single target in square brackets,
the object must be . . .
The empty target list case could also be merged. Then the only differentiation is between a single target (no comma, optional round brackets) and iterable unpacking.
|
|||
| msg319743 - (view) | Author: Julien Palard (mdk) * ![]() |
Date: 2018-06-16 14:52 | |
Agree, the empty list could be merged, the only special-case is the "single item in parenthesis", as always.
I'm still exploring the path to simplicity over explicitly listing everything (but in the reference, explicitly listing could be what we need):
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 in parentheses: The object is assigned to that target.
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.
What do you think? Should we go full-explicit, with trailing comas and everything?
|
|||
| msg319797 - (view) | Author: Martin Panter (martin.panter) * ![]() |
Date: 2018-06-16 23:52 | |
I think it is okay to leave out the options for the unpacking case. But I think it is worth clarifying that the single-target case also applies without parentheses, but that it doesn’t apply if there is a trailing comma. So: ‘‘‘ If the target list is a single target with no trailing comma, optionally in parentheses, the object is assigned to that target. Else the object must be an iterable . . . ’’’ |
|||
| msg329511 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2018-11-09 12:27 | |
I think that the fact that `(a) = 42` is accepted is rather an implementation detail, and the consequence of limitations of the grammar parser. It accepts arbitrary expression at the left hand side of assignment. After transforming CST to AST unsuitable targets are rejected, but information about grouping parenthesis is lost at this stage. This can be fixed if check the left hand side node before converting to AST. |
|||
| msg329554 - (view) | Author: Guido van Rossum (gvanrossum) * ![]() |
Date: 2018-11-09 20:13 | |
I would like to see this fixed. On Fri, Nov 9, 2018 at 4:27 AM Serhiy Storchaka <report@bugs.python.org> wrote: > > Serhiy Storchaka <storchaka+cpython@gmail.com> added the comment: > > I think that the fact that `(a) = 42` is accepted is rather an > implementation detail, and the consequence of limitations of the grammar > parser. It accepts arbitrary expression at the left hand side of > assignment. After transforming CST to AST unsuitable targets are rejected, > but information about grouping parenthesis is lost at this stage. > > This can be fixed if check the left hand side node before converting to > AST. > > ---------- > nosy: +gvanrossum, serhiy.storchaka > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue33878> > _______________________________________ > -- --Guido (mobile) |
|||
| msg329697 - (view) | Author: Julien Palard (mdk) * ![]() |
Date: 2018-11-11 23:59 | |
New changeset 082875dcd6d482558e5f1da97a1c801d60b3ed5b by Julien Palard in branch 'master': bpo-33878: Doc: Fix missing case by simplifying. (GH-7762) https://github.com/python/cpython/commit/082875dcd6d482558e5f1da97a1c801d60b3ed5b |
|||
| msg329701 - (view) | Author: Julien Palard (mdk) * ![]() |
Date: 2018-11-12 00:24 | |
New changeset aa493b5c18463ab45c087564e287643606f004ca by Julien Palard (Miss Islington (bot)) in branch '3.7': bpo-33878: Doc: Fix missing case by simplifying. (GH-7762) https://github.com/python/cpython/commit/aa493b5c18463ab45c087564e287643606f004ca |
|||
| msg329702 - (view) | Author: Julien Palard (mdk) * ![]() |
Date: 2018-11-12 00:24 | |
New changeset d0ebbf4895439233c8398dbdd0456d07132b2a6f by Julien Palard (Miss Islington (bot)) in branch '3.6': bpo-33878: Doc: Fix missing case by simplifying. (GH-7762) https://github.com/python/cpython/commit/d0ebbf4895439233c8398dbdd0456d07132b2a6f |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:01 | admin | set | github: 78059 |
| 2018-11-12 00:37:25 | mdk | set | status: open -> closed resolution: fixed stage: patch review -> resolved |
| 2018-11-12 00:24:44 | mdk | set | messages: + msg329702 |
| 2018-11-12 00:24:33 | mdk | set | messages: + msg329701 |
| 2018-11-11 23:59:59 | miss-islington | set | pull_requests: + pull_request9744 |
| 2018-11-11 23:59:50 | miss-islington | set | pull_requests: + pull_request9743 |
| 2018-11-11 23:59:42 | mdk | set | messages: + msg329697 |
| 2018-11-11 01:27:38 | emilyemorehouse | set | nosy:
+ emilyemorehouse |
| 2018-11-10 04:15:13 | pablogsal | set | pull_requests: + pull_request9719 |
| 2018-11-09 20:13:07 | gvanrossum | set | messages: + msg329554 |
| 2018-11-09 12:27:25 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka, gvanrossum messages: + msg329511 |
| 2018-06-17 10:47:16 | mdk | set | keywords:
+ patch stage: patch review pull_requests: + pull_request7370 |
| 2018-06-16 23:52:17 | martin.panter | set | messages: + msg319797 |
| 2018-06-16 14:52:59 | mdk | set | messages: + msg319743 |
| 2018-06-16 13:32:49 | martin.panter | set | messages: + msg319737 |
| 2018-06-16 13:01:46 | mdk | create | |
