Author: Amaury Forgeot d'Arc <[email protected]>
Branch:
Changeset: r57307:90debdd98abb
Date: 2012-09-12 21:12 +0200
http://bitbucket.org/pypy/pypy/changeset/90debdd98abb/
Log: Issue1260: sys.exc_info was not set before entering a context
manager's __exit__
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -966,6 +966,7 @@
isinstance(unroller, SApplicationException))
if is_app_exc:
operr = unroller.operr
+ self.last_exception = operr
w_traceback = self.space.wrap(operr.get_traceback())
w_suppress = self.call_contextmanager_exit_function(
w_exitfunc,
diff --git a/pypy/interpreter/test/test_syntax.py
b/pypy/interpreter/test/test_syntax.py
--- a/pypy/interpreter/test/test_syntax.py
+++ b/pypy/interpreter/test/test_syntax.py
@@ -567,6 +567,24 @@
import types
assert isinstance(acontextfact.exit_params[2], types.TracebackType)
+ def test_with_reraise_exception(self):
+ class Context:
+ def __enter__(self):
+ self.calls = []
+ def __exit__(self, exc_type, exc_value, exc_tb):
+ self.calls.append('exit')
+ raise
+
+ c = Context()
+ try:
+ with c:
+ 1 / 0
+ except ZeroDivisionError:
+ pass
+ else:
+ raise AssertionError('Should have reraised initial exception')
+ assert c.calls == ['exit']
+
def test_with_break(self):
s = """
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit