mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
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.
This commit is contained in:
parent
4f3c5616cc
commit
db26f7c137
4 changed files with 36 additions and 10 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue