[pypy-svn] r66289 - in pypy/branch/parser-compiler/pypy/interpreter/astcompiler: . test

benjamin at codespeak.net benjamin at codespeak.net
Thu Jul 16 16:06:32 CEST 2009


Author: benjamin
Date: Thu Jul 16 16:06:31 2009
New Revision: 66289

Modified:
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/symtable.py
   pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_symtable.py
Log:
fix bug with yield and return detection

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/symtable.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/symtable.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/symtable.py	Thu Jul 16 16:06:31 2009
@@ -193,10 +193,11 @@
         self.is_generator = True
 
     def note_return(self, ret):
-        if self.is_generator and ret.value:
-            raise SyntaxError("return with value in generator", ret.lineno,
-                              ret.col_offset)
-        self.return_with_value = True
+        if ret.value:
+            if self.is_generator:
+                raise SyntaxError("return with value in generator", ret.lineno,
+                                  ret.col_offset)
+            self.return_with_value = True
 
     def note_exec(self, exc):
         Scope.note_exec(self, exc)

Modified: pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_symtable.py
==============================================================================
--- pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_symtable.py	(original)
+++ pypy/branch/parser-compiler/pypy/interpreter/astcompiler/test/test_symtable.py	Thu Jul 16 16:06:31 2009
@@ -312,6 +312,7 @@
             input = "def f():\n    " + input
             exc = py.test.raises(SyntaxError, self.func_scope, input).value
             assert exc.msg == "return with value in generator"
+        scp = self.func_scope("def f():\n    return\n    yield x")
 
     def test_return(self):
         for input in ("class x: return", "return"):



More information about the Pypy-commit mailing list