[pypy-svn] r18009 - in pypy/dist/pypy/interpreter: astcompiler test
ac at codespeak.net
ac at codespeak.net
Fri Sep 30 17:17:19 CEST 2005
Author: ac
Date: Fri Sep 30 17:17:19 2005
New Revision: 18009
Modified:
pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
pypy/dist/pypy/interpreter/test/test_compiler.py
Log:
Reject 'yield' inside a 'try: ... finally:' block
Modified: pypy/dist/pypy/interpreter/astcompiler/pycodegen.py
==============================================================================
--- pypy/dist/pypy/interpreter/astcompiler/pycodegen.py (original)
+++ pypy/dist/pypy/interpreter/astcompiler/pycodegen.py Fri Sep 30 17:17:19 2005
@@ -1012,6 +1012,11 @@
self.emit('RETURN_VALUE')
def visitYield(self, node):
+ kind, block = self.setups.top()
+ if kind == TRY_FINALLY:
+ raise SyntaxError("'yield' not allowed in a 'try' block "
+ "with a 'finally' clause",
+ node.lineno)
self.set_lineno(node)
node.value.accept( self )
self.emit('YIELD_VALUE')
Modified: pypy/dist/pypy/interpreter/test/test_compiler.py
==============================================================================
--- pypy/dist/pypy/interpreter/test/test_compiler.py (original)
+++ pypy/dist/pypy/interpreter/test/test_compiler.py Fri Sep 30 17:17:19 2005
@@ -215,6 +215,13 @@
ex.normalize_exception(self.space)
assert ex.match(self.space, self.space.w_SyntaxError)
+ def test_yield_in_finally(self):
+ code ='def f():\n try:\n yield 19\n finally:\n pass\n'
+ e = py.test.raises(OperationError, self.compiler.compile, code, '', 'single', 0)
+ ex = e.value
+ ex.normalize_exception(self.space)
+ assert ex.match(self.space, self.space.w_SyntaxError)
+
def test_none_assignment(self):
stmts = [
'None = 0',
@@ -322,6 +329,10 @@
def test_return_in_generator(self):
py.test.skip('INPROGRES')
+ def test_yield_in_finally(self):
+ py.test.skip('INPROGRES')
+
+
class TestPyCCompiler(BaseTestCompiler):
def setup_method(self, method):
self.compiler = CPythonCompiler(self.space)
@@ -336,6 +347,9 @@
def test_return_in_generator(self):
py.test.skip('INPROGRES')
+ def test_yield_in_finally(self):
+ py.test.skip('INPROGRES')
+
class TestPythonAstCompiler(BaseTestCompiler):
def setup_method(self, method):
self.compiler = PythonAstCompiler(self.space)
More information about the Pypy-commit
mailing list