Revert "closes bpo-27494: Fix 2to3 handling of trailing comma after a… · python/cpython@9ecbe33 · GitHub
Skip to content

Commit 9ecbe33

Browse files
Revert "closes bpo-27494: Fix 2to3 handling of trailing comma after a generator expression (GH-3771)" (GH-8241)
This reverts commit af810b3. This is not valid syntax (see bpo-32012). (cherry picked from commit 4b8a7f5) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent a621f40 commit 9ecbe33

7 files changed

Lines changed: 12 additions & 36 deletions

File tree

Lib/lib2to3/Grammar.txt

Lines changed: 3 additions & 22 deletions

Lib/lib2to3/fixer_util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ def ListComp(xp, fp, it, test=None):
101101
test.prefix = " "
102102
if_leaf = Leaf(token.NAME, "if")
103103
if_leaf.prefix = " "
104-
inner_args.append(Node(syms.old_comp_if, [if_leaf, test]))
105-
inner = Node(syms.listmaker, [xp, Node(syms.old_comp_for, inner_args)])
104+
inner_args.append(Node(syms.comp_if, [if_leaf, test]))
105+
inner = Node(syms.listmaker, [xp, Node(syms.comp_for, inner_args)])
106106
return Node(syms.atom,
107107
[Leaf(token.LBRACE, "["),
108108
inner,
@@ -208,7 +208,7 @@ def attr_chain(obj, attr):
208208
next = getattr(next, attr)
209209

210210
p0 = """for_stmt< 'for' any 'in' node=any ':' any* >
211-
| old_comp_for< 'for' any 'in' node=any any* >
211+
| comp_for< 'for' any 'in' node=any any* >
212212
"""
213213
p1 = """
214214
power<

Lib/lib2to3/fixes/fix_dict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def transform(self, node, results):
8383
p1 = patcomp.compile_pattern(P1)
8484

8585
P2 = """for_stmt< 'for' any 'in' node=any ':' any* >
86-
| old_comp_for< 'for' any 'in' node=any any* >
86+
| comp_for< 'for' any 'in' node=any any* >
8787
"""
8888
p2 = patcomp.compile_pattern(P2)
8989

Lib/lib2to3/fixes/fix_paren.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class FixParen(fixer_base.BaseFix):
1515
PATTERN = """
1616
atom< ('[' | '(')
1717
(listmaker< any
18-
old_comp_for<
18+
comp_for<
1919
'for' NAME 'in'
2020
target=testlist_safe< any (',' any)+ [',']
2121
>
@@ -24,7 +24,7 @@ class FixParen(fixer_base.BaseFix):
2424
>
2525
|
2626
testlist_gexp< any
27-
old_comp_for<
27+
comp_for<
2828
'for' NAME 'in'
2929
target=testlist_safe< any (',' any)+ [',']
3030
>

Lib/lib2to3/fixes/fix_xrange.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def transform_range(self, node, results):
5555
p1 = patcomp.compile_pattern(P1)
5656

5757
P2 = """for_stmt< 'for' any 'in' node=any ':' any* >
58-
| old_comp_for< 'for' any 'in' node=any any* >
58+
| comp_for< 'for' any 'in' node=any any* >
5959
| comparison< any 'in' node=any any*>
6060
"""
6161
p2 = patcomp.compile_pattern(P2)

Lib/lib2to3/tests/test_parser.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,6 @@ def test_multiline_str_literals(self):
612612
self.validate(s)
613613

614614

615-
class TestGeneratorExpressions(GrammarTest):
616-
617-
def test_trailing_comma_after_generator_expression_argument_works(self):
618-
# BPO issue 27494
619-
self.validate("set(x for x in [],)")
620-
621-
622615
def diff_texts(a, b, filename):
623616
a = a.splitlines()
624617
b = b.splitlines()
Lines changed: 2 additions & 0 deletions

0 commit comments

Comments
 (0)