[pypy-commit] pypy py3.5-async: Throw SyntaxError if 'yield from' inside async function (fixes test_invalid_7 in test_syntax)

raffael_t pypy.commits at gmail.com
Mon Jul 11 12:18:29 EDT 2016


Author: Raffael Tfirst <raffael.tfirst at gmail.com>
Branch: py3.5-async
Changeset: r85658:e779f313fab5
Date: 2016-07-11 18:17 +0200
http://bitbucket.org/pypy/pypy/changeset/e779f313fab5/

Log:	Throw SyntaxError if 'yield from' inside async function (fixes
	test_invalid_7 in test_syntax)

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
@@ -88,6 +88,11 @@
         """Called when a yield is found."""
         raise SyntaxError("'yield' outside function", yield_node.lineno,
                           yield_node.col_offset)
+    
+    def note_yieldFrom(self, yield_node):
+        """Called when a yield from is found."""
+        raise SyntaxError("'yield' outside function", yield_node.lineno,
+                          yield_node.col_offset)
 
     def note_return(self, ret):
         """Called when a return statement is found."""
@@ -249,6 +254,11 @@
         self.is_generator = True
         if self._in_try_body_depth > 0:
             self.has_yield_inside_try = True
+    
+    def note_yieldFrom(self, yield_node):
+        self.is_generator = True
+        if self._in_try_body_depth > 0:
+            self.has_yield_inside_try = True
 
     def note_return(self, ret):
         if ret.value:
@@ -288,10 +298,13 @@
         FunctionScope.__init__(self, name, lineno, col_offset)
 
     def note_yield(self, yield_node):
-        """Called when a yield is found."""
         raise SyntaxError("'yield' inside async function", yield_node.lineno,
                           yield_node.col_offset)
 
+    def note_yieldFrom(self, yield_node):
+        raise SyntaxError("'yield from' inside async function", yield_node.lineno,
+                          yield_node.col_offset)
+
 class ClassScope(Scope):
 
     _hide_bound_from_nested_scopes = True
@@ -448,7 +461,7 @@
         ast.GenericASTVisitor.visit_Yield(self, yie)
 
     def visit_YieldFrom(self, yfr):
-        self.scope.note_yield(yfr)
+        self.scope.note_yieldFrom(yfr)
         ast.GenericASTVisitor.visit_YieldFrom(self, yfr)
 
     def visit_Global(self, glob):


More information about the pypy-commit mailing list