summaryrefslogtreecommitdiffstats
path: root/Grammar
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2001-10-15 15:44:05 (GMT)
committerGuido van Rossum <guido@python.org>2001-10-15 15:44:05 (GMT)
commit1c917072ca2895a196de7f397d4e96bcc577e13d (patch)
tree866e2babdb9b21e5869012c583a191898ac68a92 /Grammar
parent69c0ff38362dff3b0a90828b8d787dfb3eb14bc3 (diff)
downloadcpython-1c917072ca2895a196de7f397d4e96bcc577e13d.zip
cpython-1c917072ca2895a196de7f397d4e96bcc577e13d.tar.gz
cpython-1c917072ca2895a196de7f397d4e96bcc577e13d.tar.bz2
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)+ [',']]
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/Grammar3
1 files changed, 2 insertions, 1 deletions
diff --git a/Grammar/Grammar b/Grammar/Grammar
index d85863e..6ac0cbc 100644
--- a/Grammar/Grammar
+++ b/Grammar/Grammar
@@ -89,6 +89,7 @@ subscript: '.' '.' '.' | test | [test] ':' [test] [sliceop]
sliceop: ':' [test]
exprlist: expr (',' expr)* [',']
testlist: test (',' test)* [',']
+testlist_safe: test [(',' test)+ [',']]
dictmaker: test ':' test (',' test ':' test)* [',']
classdef: 'class' NAME ['(' testlist ')'] ':' suite
@@ -97,5 +98,5 @@ arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test)
argument: [test '='] test # Really [keyword '='] test
list_iter: list_for | list_if
-list_for: 'for' exprlist 'in' testlist [list_iter]
+list_for: 'for' exprlist 'in' testlist_safe [list_iter]
list_if: 'if' test [list_iter]