Revert "closes bpo-27494: Fix 2to3 handling of trailing comma after a generator expression (#3771)" by serhiy-storchaka · Pull Request #8241 · python/cpython · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 3 additions & 22 deletions Lib/lib2to3/Grammar.txt
6 changes: 3 additions & 3 deletions Lib/lib2to3/fixer_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ def ListComp(xp, fp, it, test=None):
test.prefix = " "
if_leaf = Leaf(token.NAME, "if")
if_leaf.prefix = " "
inner_args.append(Node(syms.old_comp_if, [if_leaf, test]))
inner = Node(syms.listmaker, [xp, Node(syms.old_comp_for, inner_args)])
inner_args.append(Node(syms.comp_if, [if_leaf, test]))
inner = Node(syms.listmaker, [xp, Node(syms.comp_for, inner_args)])
return Node(syms.atom,
[Leaf(token.LBRACE, "["),
inner,
Expand Down Expand Up @@ -208,7 +208,7 @@ def attr_chain(obj, attr):
next = getattr(next, attr)

p0 = """for_stmt< 'for' any 'in' node=any ':' any* >
| old_comp_for< 'for' any 'in' node=any any* >
| comp_for< 'for' any 'in' node=any any* >
"""
p1 = """
power<
Expand Down
2 changes: 1 addition & 1 deletion Lib/lib2to3/fixes/fix_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def transform(self, node, results):
p1 = patcomp.compile_pattern(P1)

P2 = """for_stmt< 'for' any 'in' node=any ':' any* >
| old_comp_for< 'for' any 'in' node=any any* >
| comp_for< 'for' any 'in' node=any any* >
"""
p2 = patcomp.compile_pattern(P2)

Expand Down
4 changes: 2 additions & 2 deletions Lib/lib2to3/fixes/fix_paren.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FixParen(fixer_base.BaseFix):
PATTERN = """
atom< ('[' | '(')
(listmaker< any
old_comp_for<
comp_for<
'for' NAME 'in'
target=testlist_safe< any (',' any)+ [',']
>
Expand All @@ -24,7 +24,7 @@ class FixParen(fixer_base.BaseFix):
>
|
testlist_gexp< any
old_comp_for<
comp_for<
'for' NAME 'in'
target=testlist_safe< any (',' any)+ [',']
>
Expand Down
2 changes: 1 addition & 1 deletion Lib/lib2to3/fixes/fix_xrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def transform_range(self, node, results):
p1 = patcomp.compile_pattern(P1)

P2 = """for_stmt< 'for' any 'in' node=any ':' any* >
| old_comp_for< 'for' any 'in' node=any any* >
| comp_for< 'for' any 'in' node=any any* >
| comparison< any 'in' node=any any*>
"""
p2 = patcomp.compile_pattern(P2)
Expand Down
7 changes: 0 additions & 7 deletions Lib/lib2to3/tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,13 +612,6 @@ def test_multiline_str_literals(self):
self.validate(s)


class TestGeneratorExpressions(GrammarTest):

def test_trailing_comma_after_generator_expression_argument_works(self):
# BPO issue 27494
self.validate("set(x for x in [],)")


def diff_texts(a, b, filename):
a = a.splitlines()
b = b.splitlines()
Expand Down