This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Unpacking without parentheses is allowed since 3.9
Type: Stage: resolved
Components: Parser Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, JelleZijlstra, erlendaasland, gvanrossum, jwilk, lys.nikolaou, miss-islington, pablogsal, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2022-02-11 18:10 by pablogsal, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 31481 merged pablogsal, 2022-02-21 22:56
Messages (11)
msg413089 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-02-11 18:10
Seems that this is allowed since the PEG parser rewrite:

for x in *a, *b:
    print(x)

but I cannot find anywhere were we discussed this. I am not sure if we should keep it or treat it as a bug and fix it.
msg413090 - (view) Author: Batuhan Taskaya (BTaskaya) * (Python committer) Date: 2022-02-11 18:13
Since this was already allowed in 3.9 and 3.10 stable relases, and since it is consistent with the RHS of an assignment (something = *a, *b); I'd lean towards keeping it (and maybe fixing the old parser's grammar to reflect that) and documenting this.
msg413091 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-02-11 18:13
I'd lean towards keeping this syntax:
- It's already been out for two releases, so there's user code out there relying on it. (In fact we found out about this because somebody complained that Black's parser couldn't handle this code.)
- The syntax isn't obviously confusing and the meaning is clear.
- It's not hard to parse; it was easy to adjust Black's parser to allow it.
msg413092 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2022-02-11 18:36
+1 (what Jelle said)
msg413098 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2022-02-11 20:56
Let's just document it for 3.11.
msg413101 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-02-11 21:44
Will prepare a PR
msg413501 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2022-02-18 18:31
Allowing no parentheses is also consistent with the following:
  for x in 1,2,3: print(x)
msg413507 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2022-02-18 19:56
Adding jwilk back (a bpo interaction with browser form caching makes this happen frequently).
msg413698 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2022-02-22 10:10
What exactly was happened? What rule was changed? Can it cause other changes which allow ambiguous code or change semantic?
msg413703 - (view) Author: Pablo Galindo Salgado (pablogsal) * (Python committer) Date: 2022-02-22 10:56
What happened is that the new grammar using the PEG parser used the equivalent of starred_testlist instead of testlist for the iterable list of for statements.

The only extra thing allowed is starred elements, that are interpreted as if you are building a tuple without parentheses.
msg413718 - (view) Author: miss-islington (miss-islington) Date: 2022-02-22 17:26
New changeset 7fb94fd7a88f14096a509dddd4d8a979a3912672 by Pablo Galindo Salgado in branch 'main':
bpo-46725: Document starred expressions in for statements (GH-31481)
https://github.com/python/cpython/commit/7fb94fd7a88f14096a509dddd4d8a979a3912672
History
Date User Action Args
2022-04-11 14:59:56adminsetgithub: 90881
2022-02-22 18:31:20pablogsalsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2022-02-22 17:26:57miss-islingtonsetnosy: + miss-islington
messages: + msg413718
2022-02-22 10:56:34pablogsalsetmessages: + msg413703
2022-02-22 10:10:41serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg413698
2022-02-21 22:56:22pablogsalsetkeywords: + patch
stage: patch review
pull_requests: + pull_request29612
2022-02-18 19:56:51gvanrossumsetnosy: + jwilk
messages: + msg413507
2022-02-18 18:31:47terry.reedysetnosy: + terry.reedy, - jwilk
messages: + msg413501
2022-02-18 18:30:04jwilksetnosy: + jwilk
2022-02-11 21:44:53pablogsalsetmessages: + msg413101
2022-02-11 20:56:50gvanrossumsetmessages: + msg413098
2022-02-11 18:36:36erlendaaslandsetnosy: + erlendaasland
messages: + msg413092
2022-02-11 18:13:35JelleZijlstrasetnosy: + JelleZijlstra
messages: + msg413091
2022-02-11 18:13:13BTaskayasetmessages: + msg413090
2022-02-11 18:10:30pablogsalcreate