mirror of
https://github.com/python/cpython.git
synced 2025-12-09 02:35:14 +00:00
PyErr_Print can leave sys.last_traceback hanging around; kill it
This commit is contained in:
parent
8af4919b37
commit
47afc2af79
1 changed files with 8 additions and 10 deletions
|
|
@ -265,28 +265,26 @@ class DisTests(unittest.TestCase):
|
||||||
self.do_disassembly_test(method_bytecode, dis_c_instance_method_bytes)
|
self.do_disassembly_test(method_bytecode, dis_c_instance_method_bytes)
|
||||||
|
|
||||||
def test_dis_none(self):
|
def test_dis_none(self):
|
||||||
|
try:
|
||||||
|
del sys.last_traceback
|
||||||
|
except AttributeError:
|
||||||
|
pass
|
||||||
self.assertRaises(RuntimeError, dis.dis, None)
|
self.assertRaises(RuntimeError, dis.dis, None)
|
||||||
|
|
||||||
def test_dis_object(self):
|
def test_dis_object(self):
|
||||||
self.assertRaises(TypeError, dis.dis, object())
|
self.assertRaises(TypeError, dis.dis, object())
|
||||||
|
|
||||||
def test_dis_traceback(self):
|
def test_dis_traceback(self):
|
||||||
not_defined = object()
|
try:
|
||||||
tb = None
|
del sys.last_traceback
|
||||||
old = getattr(sys, 'last_traceback', not_defined)
|
except AttributeError:
|
||||||
|
pass
|
||||||
def cleanup():
|
|
||||||
if old is not not_defined:
|
|
||||||
sys.last_traceback = old
|
|
||||||
else:
|
|
||||||
del sys.last_traceback
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
1/0
|
1/0
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
tb = e.__traceback__
|
tb = e.__traceback__
|
||||||
sys.last_traceback = tb
|
sys.last_traceback = tb
|
||||||
self.addCleanup(cleanup)
|
|
||||||
|
|
||||||
tb_dis = self.get_disassemble_as_string(tb.tb_frame.f_code, tb.tb_lasti)
|
tb_dis = self.get_disassemble_as_string(tb.tb_frame.f_code, tb.tb_lasti)
|
||||||
self.do_disassembly_test(None, tb_dis)
|
self.do_disassembly_test(None, tb_dis)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue