Issue 25070: Python 2.6 - Python 3.4 allows unparenthesized generator with *args, **kw, forbidden in 3.5 (original) (raw)

Created on 2015-09-11 13:03 by ztane, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (10)
msg250468 - (view) Author: Antti Haapala (ztane) * Date: 2015-09-11 13:03
User DeTeReR asked a question (http://stackoverflow.com/questions/32521140/generator-as-function-argument) on Stack Overflow about a special case of code that seemed to work in Python 3.4: f(1 for x in [1], *[2]) and f(*[2], 1 for x in [1]) I found out that when Python 2.6 introduced the "keyword arguments after *args", the checks in ast.c did not follow: for (i = 0; i < NCH(n); i++) { node *ch = CHILD(n, i); if (TYPE(ch) == argument) { if (NCH(ch) == 1) nargs++; else if (TYPE(CHILD(ch, 1)) == gen_for) ngens++; else nkeywords++; } } if (ngens > 1 | (ngens && (nargs
msg250469 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2015-09-11 13:15
I guess that it's a consequence of the PEP 448 "additional unpacking generalizations".
msg250470 - (view) Author: Antti Haapala (ztane) * Date: 2015-09-11 13:25
@haypo yes. I must add that I found out that Python 2.5 also allows f(1 for x in [1], *a) and f(1 for x in [1], **kw) but not f(*a, 1 for x in [1]) So I do not know if the first and second cases were intentional or not. Also, in Python 2.6 - 3.4, f(*a, 1 for x in [1]) provides the generator as the *first* positional argument, in 3.5 it'd be the last one.
msg250471 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-09-11 13:46
According to the human readable grammar in the docs https://docs.python.org/3/reference/expressions.html#calls I'd say this was a bug that is now fixed in 3.5. The call should either take a single unparenthesized generator expression or an argument_list (which may contain parenthesized generator expressions).
msg250473 - (view) Author: Antti Haapala (ztane) * Date: 2015-09-11 13:50
Yeah, it is a bug in 2.5 too; https://docs.python.org/2.5/ref/calls.html call ::= primary "(" [argument_list [","] | expression genexpr_for] ")"
msg250500 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-09-11 21:40
If we have decided that this is a "fixed bug", it should indeed be mentioned in what's new for 3.5 since it is a behavior change.
msg250511 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-09-12 03:36
> If we have decided that this is a "fixed bug", [..] I'd call this a bug fix. The old syntax was completely unreadable. Should I close this issue? > [..] it should indeed be mentioned in what's new for 3.5 since it is a behavior change. Sure, I'll document it.
msg250519 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2015-09-12 12:10
I think the issue can be closed (after updating "what's new"). Even if we wanted to keep backwards compatibility, it's too late now.
msg250535 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2015-09-12 21:51
New changeset 10a9d4acd9cb by Yury Selivanov in branch '3.5': whatsnew/3.5 More edits https://hg.python.org/cpython/rev/10a9d4acd9cb
msg250536 - (view) Author: Yury Selivanov (yselivanov) * (Python committer) Date: 2015-09-12 21:52
What's new is now updated with description of this issue. Closing it now.
History
Date User Action Args
2022-04-11 14:58:20 admin set github: 69257
2015-09-12 21:52:41 yselivanov set status: open -> closedresolution: wont fixmessages: + stage: resolved
2015-09-12 21:51:23 python-dev set nosy: + python-devmessages: +
2015-09-12 12:10:46 skrah set messages: +
2015-09-12 03:36:39 yselivanov set messages: +
2015-09-12 03:28:12 terry.reedy set versions: - Python 3.2, Python 3.3
2015-09-11 21:40:29 r.david.murray set nosy: + r.david.murraymessages: +
2015-09-11 13:50:47 ztane set nosy: + docs@pythonmessages: + assignee: docs@pythoncomponents: + Documentation
2015-09-11 13:46:51 skrah set nosy: + skrahmessages: +
2015-09-11 13:25:48 ztane set messages: +
2015-09-11 13:15:52 vstinner set nosy: + vstinner, yselivanovmessages: +
2015-09-11 13:03:44 ztane create