[New-bugs-announce] [issue42482] TracebackException should not hold reference to the exception traceback
Irit Katriel
report at bugs.python.org
Fri Nov 27 05:11:08 EST 2020
New submission from Irit Katriel <iritkatriel at yahoo.com>:
TracebackException holds a reference to the exc_traceback, which is wrong because (1) it's supposed to capture the output without holding references to real things. (2) it makes comparison wrong for equivalent exceptions, as in this example:
------------------------------------------
import sys
import traceback
excs = []
for _ in range(2):
try:
1/0
except:
excs.append(traceback.TracebackException(*sys.exc_info()))
print('formats equal: ', list(excs[0].format()) == list(excs[0].format()))
print('excs equal: ', excs[0] == excs[1])
excs[0].exc_traceback = excs[1].exc_traceback = None
print('excs equal w/o exc_traceback: ', excs[0] == excs[1])
------------------------------------------
Output:
formats equal: True
excs equal: False
excs equal w/o exc_traceback: True
------------------------------------------
The good news is that it's only used to check for non-None (added here https://bugs.python.org/issue24695) so should be easy to remove.
----------
components: Library (Lib)
messages: 381938
nosy: iritkatriel
priority: normal
severity: normal
status: open
title: TracebackException should not hold reference to the exception traceback
type: behavior
versions: Python 3.10, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42482>
_______________________________________
More information about the New-bugs-announce
mailing list