Author: Armin Rigo <ar...@tunes.org> Branch: py3.5-corowrapper Changeset: r87213:14723a241c8a Date: 2016-09-18 23:09 +0200 http://bitbucket.org/pypy/pypy/changeset/14723a241c8a/
Log: Another test and fix diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py --- a/pypy/interpreter/generator.py +++ b/pypy/interpreter/generator.py @@ -164,8 +164,7 @@ try: self.next_yield_from(frame, w_yf, w_arg_or_err) except OperationError as operr: - ec = space.getexecutioncontext() - return frame.handle_operation_error(ec, operr) + return frame.handle_generator_error(operr) # Normal case: the call above raises Yield. # We reach this point if the iterable is exhausted. last_instr = jit.promote(frame.last_instr) @@ -173,8 +172,7 @@ return r_uint(last_instr + 1) if isinstance(w_arg_or_err, SApplicationException): - ec = space.getexecutioncontext() - return frame.handle_operation_error(ec, w_arg_or_err.operr) + return frame.handle_generator_error(w_arg_or_err.operr) last_instr = jit.promote(frame.last_instr) if last_instr == -1: diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py --- a/pypy/interpreter/pyopcode.py +++ b/pypy/interpreter/pyopcode.py @@ -101,6 +101,12 @@ operr = OperationError(w_type, w_value) return self.handle_operation_error(ec, operr) + def handle_generator_error(self, operr): + # for generator.py + ec = self.space.getexecutioncontext() + operr.record_context(self.space, self) + return self.handle_operation_error(ec, operr) + def handle_operation_error(self, ec, operr, attach_tb=True): if attach_tb: if 1: diff --git a/pypy/interpreter/test/test_generator.py b/pypy/interpreter/test/test_generator.py --- a/pypy/interpreter/test/test_generator.py +++ b/pypy/interpreter/test/test_generator.py @@ -694,6 +694,24 @@ 2, ] + def test_exception_context(self): """ + import operator + def f(): + try: + raise ValueError + except ValueError: + yield from map(operator.truediv, [2, 3], [4, 0]) + gen = f() + assert next(gen) == 0.5 + try: + next(gen) + except ZeroDivisionError as e: + assert e.__context__ is not None + assert isinstance(e.__context__, ValueError) + else: + assert False, "should have raised" + """ + class AppTestGeneratorStop: _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit