@@ -111,8 +111,8 @@ atom: ('(' [yield_expr|testlist_gexp] ')' |
111111 '{' [dictsetmaker] '}' |
112112 '`' testlist1 '`' |
113113 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))* [','] )
116116lambdef: 'lambda' [varargslist] ':' test
117117trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME
118118subscriptlist: subscript (',' subscript)* [',']
@@ -142,28 +142,9 @@ argument: ( test [comp_for] |
142142 star_expr )
143143
144144comp_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]
146146comp_if: 'if' old_test [comp_iter]
147147
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-
167148testlist1: test (',' test)*
168149
169150# not used in grammar, but may appear in "node" passed from Parser to Compiler
0 commit comments