mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
Very subtle syntax change: in a list comprehension, the testlist in
"for <var> in <testlist> may no longer be a single test followed by a comma. This solves SF bug #431886. Note that if the testlist contains more than one test, a trailing comma is still allowed, for maximum backward compatibility; but this example is not: [(x, y) for x in range(10), for y in range(10)] ^ The fix involved creating a new nonterminal 'testlist_safe' whose definition doesn't allow the trailing comma if there's only one test: testlist_safe: test [(',' test)+ [',']]
This commit is contained in:
parent
69c0ff3836
commit
1c917072ca
5 changed files with 180 additions and 141 deletions
|
@ -1039,6 +1039,14 @@ validate_testlist(node *tree)
|
|||
}
|
||||
|
||||
|
||||
static int
|
||||
validate_testlist_safe(node *tree)
|
||||
{
|
||||
return (validate_repeating_list(tree, testlist_safe,
|
||||
validate_test, "testlist_safe"));
|
||||
}
|
||||
|
||||
|
||||
/* '*' NAME [',' '**' NAME] | '**' NAME
|
||||
*/
|
||||
static int
|
||||
|
@ -1218,7 +1226,7 @@ validate_list_for(node *tree)
|
|||
res = (validate_name(CHILD(tree, 0), "for")
|
||||
&& validate_exprlist(CHILD(tree, 1))
|
||||
&& validate_name(CHILD(tree, 2), "in")
|
||||
&& validate_testlist(CHILD(tree, 3)));
|
||||
&& validate_testlist_safe(CHILD(tree, 3)));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue