diff options
author | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-08-29 07:13:32 (GMT) |
---|---|---|
committer | Amaury Forgeot d'Arc <amauryfa@gmail.com> | 2008-08-29 07:13:32 (GMT) |
commit | db26f7c13748db526e52501d3ba2856a6e30c7a5 (patch) | |
tree | 543064580b5daedb94549cb8bcf5396172492f6b /Lib/test | |
parent | 4f3c5616ccb880f8b5602c2da5c8951b55e4e9dd (diff) | |
download | cpython-db26f7c13748db526e52501d3ba2856a6e30c7a5.zip cpython-db26f7c13748db526e52501d3ba2856a6e30c7a5.tar.gz cpython-db26f7c13748db526e52501d3ba2856a6e30c7a5.tar.bz2 |
Issue 3611: in some cases (a __del__ re-raising an exception, when called from inside
an 'except' clause), the exception __context__ would be reset to None.
This crases the interpreter if this precisely happens inside PyErr_SetObject.
- now the __context__ is properly preserved
- in any case, PyErr_SetObject now saves the current exc_value in a local variable, to
avoid such crashes in the future.
Reviewer: Antoine Pitrou.
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_raise.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Lib/test/test_raise.py b/Lib/test/test_raise.py index 4537e9a..5a63b86 100644 --- a/Lib/test/test_raise.py +++ b/Lib/test/test_raise.py @@ -324,6 +324,30 @@ class TestContext(unittest.TestCase): f() + def test_3611(self): + # A re-raised exception in a __del__ caused the __context__ + # to be cleared + class C: + def __del__(self): + try: + 1/0 + except: + raise + + def f(): + x = C() + try: + try: + x.x + except AttributeError: + del x + raise TypeError + except Exception as e: + self.assertNotEqual(e.__context__, None) + self.assert_(isinstance(e.__context__, AttributeError)) + + with support.captured_output("stderr"): + f() class TestRemovedFunctionality(unittest.TestCase): def test_tuples(self): |