Revert "closes bpo-27494: Fix 2to3 handling of trailing comma after a… · python/cpython@9ecbe33 (original) (raw)
`@@ -111,8 +111,8 @@ atom: ('(' [yield_expr|testlist_gexp] ')' |
`
111
111
` '{' [dictsetmaker] '}' |
`
112
112
`` '' testlist1 '
' |
``
113
113
` NAME | NUMBER | STRING+ | '.' '.' '.')
`
114
``
`-
listmaker: (test|star_expr) ( old_comp_for | (',' (test|star_expr))* [','] )
`
115
``
`-
testlist_gexp: (test|star_expr) ( old_comp_for | (',' (test|star_expr))* [','] )
`
``
114
`+
listmaker: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
`
``
115
`+
testlist_gexp: (test|star_expr) ( comp_for | (',' (test|star_expr))* [','] )
`
116
116
`lambdef: 'lambda' [varargslist] ':' test
`
117
117
`trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
`
118
118
`subscriptlist: subscript (',' subscript)* [',']
`
`@@ -142,28 +142,9 @@ argument: ( test [comp_for] |
`
142
142
` star_expr )
`
143
143
``
144
144
`comp_iter: comp_for | comp_if
`
145
``
`-
comp_for: [ASYNC] 'for' exprlist 'in' or_test [comp_iter]
`
``
145
`+
comp_for: [ASYNC] 'for' exprlist 'in' testlist_safe [comp_iter]
`
146
146
`comp_if: 'if' old_test [comp_iter]
`
147
147
``
148
``
`-
As noted above, testlist_safe extends the syntax allowed in list
`
149
``
`-
comprehensions and generators. We can't use it indiscriminately in all
`
150
``
`-
derivations using a comp_for-like pattern because the testlist_safe derivation
`
151
``
`-
contains comma which clashes with trailing comma in arglist.
`
152
``
`-
`
153
``
`-
This was an issue because the parser would not follow the correct derivation
`
154
``
`-
when parsing syntactically valid Python code. Since testlist_safe was created
`
155
``
`-
specifically to handle list comprehensions and generator expressions enclosed
`
156
``
`-
with parentheses, it's safe to only use it in those. That avoids the issue; we
`
157
``
`-
can parse code like set(x for x in [],).
`
158
``
`-
`
159
``
`-
The syntax supported by this set of rules is not a valid Python 3 syntax,
`
160
``
`-
hence the prefix "old".
`
161
``
`-
`
162
``
`-
See https://bugs.python.org/issue27494
`
163
``
`-
old_comp_iter: old_comp_for | old_comp_if
`
164
``
`-
old_comp_for: [ASYNC] 'for' exprlist 'in' testlist_safe [old_comp_iter]
`
165
``
`-
old_comp_if: 'if' old_test [old_comp_iter]
`
166
``
-
167
148
`testlist1: test (',' test)*
`
168
149
``
169
150
`# not used in grammar, but may appear in "node" passed from Parser to Compiler
`