Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: py3.7
Changeset: r98660:57f3cbe9b2fa
Date: 2020-02-03 22:31 +0100
http://bitbucket.org/pypy/pypy/changeset/57f3cbe9b2fa/

Log:    f(x for x in y, ) raises an error now

diff --git a/pypy/interpreter/astcompiler/astbuilder.py 
b/pypy/interpreter/astcompiler/astbuilder.py
--- a/pypy/interpreter/astcompiler/astbuilder.py
+++ b/pypy/interpreter/astcompiler/astbuilder.py
@@ -1089,6 +1089,7 @@
         arg_count = 0 # position args + iterable args unpackings
         keyword_count = 0 # keyword args + keyword args unpackings
         generator_count = 0
+        last_is_comma = False
         for i in range(args_node.num_children()):
             argument = args_node.get_child(i)
             if argument.type == syms.argument:
@@ -1102,8 +1103,11 @@
                     # argument.get_child(0).type == tokens.DOUBLESTAR
                     # or keyword arg
                     keyword_count += 1
-        if generator_count > 1 or \
-                (generator_count and (keyword_count or arg_count)):
+            last_is_comma = argument.type == tokens.COMMA
+
+        if (generator_count > 1 or
+                (generator_count and (keyword_count or arg_count)) or
+                (generator_count == 1 and last_is_comma)):
             self.error("Generator expression must be parenthesized "
                        "if not sole argument", args_node)
         args = []
diff --git a/pypy/interpreter/astcompiler/test/test_astbuilder.py 
b/pypy/interpreter/astcompiler/test/test_astbuilder.py
--- a/pypy/interpreter/astcompiler/test/test_astbuilder.py
+++ b/pypy/interpreter/astcompiler/test/test_astbuilder.py
@@ -1073,6 +1073,10 @@
         exc = pytest.raises(SyntaxError, self.get_ast, input).value
         assert exc.msg == "Generator expression must be parenthesized if not " 
\
             "sole argument"
+        input = "f(x for x in y, )"
+        exc = pytest.raises(SyntaxError, self.get_ast, input).value
+        assert exc.msg == "Generator expression must be parenthesized if not " 
\
+            "sole argument"
         many_args = ", ".join("x%i" % i for i in range(256))
         input = "f(%s)" % (many_args,)
         self.get_ast(input) # doesn't crash any more
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to