[pypy-commit] pypy py3.6: Raise SyntaxError when 'return' with value is used inside an async generator.

mjacob pypy.commits at gmail.com
Tue Mar 20 09:11:26 EDT 2018


Author: Manuel Jacob <me at manueljacob.de>
Branch: py3.6
Changeset: r94027:1938b1ea9975
Date: 2018-03-20 14:10 +0100
http://bitbucket.org/pypy/pypy/changeset/1938b1ea9975/

Log:	Raise SyntaxError when 'return' with value is used inside an async
	generator.

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
@@ -263,6 +263,9 @@
 
     def note_return(self, ret):
         if ret.value:
+            if self.is_coroutine and self.is_generator:
+                raise SyntaxError("'return' with value in async generator",
+                                  ret.lineno, ret.col_offset)
             self.return_with_value = True
             self.ret = ret
 
diff --git a/pypy/interpreter/test/test_syntax.py b/pypy/interpreter/test/test_syntax.py
--- a/pypy/interpreter/test/test_syntax.py
+++ b/pypy/interpreter/test/test_syntax.py
@@ -94,6 +94,10 @@
     async def foo():
         await await fut
 
+    async def foo():
+        yield
+        return 42
+
 """)
 
 


More information about the pypy-commit mailing list