New submission from Irit Katriel <iritkatr...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue42482>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to