Author: Ronan Lamy <ronan.l...@gmail.com> Branch: py3.5 Changeset: r88144:7c88b941e3a8 Date: 2016-11-04 23:07 +0000 http://bitbucket.org/pypy/pypy/changeset/7c88b941e3a8/
Log: Test and fix for an annoying issue diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py --- a/pypy/interpreter/generator.py +++ b/pypy/interpreter/generator.py @@ -162,6 +162,7 @@ try: self.next_yield_from(frame, w_yf, w_arg_or_err) except OperationError as operr: + operr.record_context(space, frame) return frame.handle_generator_error(operr) # Normal case: the call above raises Yield. # We reach this point if the iterable is exhausted. diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py --- a/pypy/interpreter/pyopcode.py +++ b/pypy/interpreter/pyopcode.py @@ -97,7 +97,6 @@ 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): 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 @@ -185,6 +185,27 @@ tb = tb.tb_next assert levels == 3 + def test_throw_context(self): + # gen.throw(exc) must not modify exc.__context__ + def gen(): + try: + yield + except: + raise ValueError + + try: + raise KeyError + except KeyError: + g = gen() + next(g) + exc1 = Exception(1) + exc2 = Exception(2) + exc2.__context__ = exc1 + try: + g.throw(exc2) + except ValueError: + assert exc2.__context__ is exc1 + def test_close(self): def f(): yield 1 @@ -637,7 +658,7 @@ sys.stderr = io.StringIO() gi.close() assert 'ZeroDivisionError' in sys.stderr.getvalue() - + def test_returning_value_from_delegated_throw(self): """ Test returning value from delegated 'throw' _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit