Author: Armin Rigo <[email protected]>
Branch: py3.5
Changeset: r89818:13beb9aa557f
Date: 2017-01-28 12:25 +0100
http://bitbucket.org/pypy/pypy/changeset/13beb9aa557f/

Log:    Issue a SyntaxWarning in a case where CPython (and PyPy) give a
        rather nonsensical result

diff --git a/pypy/interpreter/astcompiler/symtable.py 
b/pypy/interpreter/astcompiler/symtable.py
--- a/pypy/interpreter/astcompiler/symtable.py
+++ b/pypy/interpreter/astcompiler/symtable.py
@@ -547,6 +547,13 @@
         for item in list(consider):
             item.walkabout(self)
         self.pop_scope()
+        # http://bugs.python.org/issue10544: was never fixed in CPython,
+        # but we can at least issue a SyntaxWarning in the meantime
+        if new_scope.is_generator:
+            msg = ("'yield' inside a list or generator comprehension behaves "
+                   "unexpectedly (http://bugs.python.org/issue10544)")
+            misc.syntax_warning(self.space, msg, self.compile_info.filename,
+                                node.lineno, node.col_offset)
 
     def visit_ListComp(self, listcomp):
         self._visit_comprehension(listcomp, listcomp.generators, listcomp.elt)
diff --git a/pypy/interpreter/test/test_compiler.py 
b/pypy/interpreter/test/test_compiler.py
--- a/pypy/interpreter/test/test_compiler.py
+++ b/pypy/interpreter/test/test_compiler.py
@@ -343,6 +343,7 @@
             assert ex.match(self.space, self.space.w_SyntaxError)
 
     def test_globals_warnings(self):
+        # also tests some other constructions that give a warning
         space = self.space
         w_mod = space.appexec((), '():\n import warnings\n return warnings\n') 
#sys.getmodule('warnings')
         w_filterwarnings = space.getattr(w_mod, space.wrap('filterwarnings'))
@@ -364,6 +365,18 @@
     print x
     x = 2
     global x
+''', '''
+def wrong_listcomp():
+    return [(yield 42) for i in j]
+''', '''
+def wrong_gencomp():
+    return ((yield 42) for i in j)
+''', '''
+def wrong_dictcomp():
+    return {(yield 42):2 for i in j}
+''', '''
+def wrong_setcomp():
+    return {(yield 42) for i in j}
 '''):
 
             space.call_args(w_filterwarnings, filter_arg)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to