Author ztane
Recipients ztane
Date 2015-09-11.13:03:43
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
User DeTeReR asked a question ( on Stack Overflow about a special case of code that seemed to work in Python 3.4:

    f(1 for x in [1], *[2])


    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)
            else if (TYPE(CHILD(ch, 1)) == gen_for)
    if (ngens > 1 || (ngens && (nargs || nkeywords))) {
        ast_error(n, "Generator expression must be parenthesized "
                  "if not sole argument");
        return NULL;

the *args, **kwargs were not considered to be of type "argument" by the Grammar, and thus the error was not generated in this case.

Further down, the error "non-keyword arg after keyword arg" was not triggered in the case of sole unparenthesized generator expression.

Now, the parsing changes in 3.5 have disallowed all of these constructs:

    f(1 for i in [42], **kw)
    f(1 for i in [42], *args)
    f(*args, 1 for i in [42])

which were (erroneously) allowed in previous versions.

I believe at least 3.5 release notes should mention this change.
Date User Action Args
2015-09-11 13:03:44ztanesetrecipients: + ztane
2015-09-11 13:03:44ztanesetmessageid: <>
2015-09-11 13:03:44ztanelinkissue25070 messages
2015-09-11 13:03:43ztanecreate