Nick Coghlan added the comment:

As Robert noted, this is a straight up error, where the clear_frames() call and 
deleting the exception traceback from the saved object aren't enough to drop 
all references to `callable_obj`.

The trick is that the cleanup code isn't accounting for __cause__ and 
__context__: it's only clearing and dropping the traceback for the topmost 
exception in the chain.

In Vjacheslav's example, there are *two* tracebacks to worry about: both the 
top level one (which is getting cleaned up) and the inner one from 
exc.__context__ which isn't being touched.

We could likely use a "traceback.clear_all_frames()" helper that walks an 
exception tree clearing *all* the traceback frames, both on the original 
exception, and on all the __cause__ and __context__ attributes.

(We can't just clear __cause__ and __context__, since those can be accessed and 
tested when using the context manager form and the `exception` attribute)

----------
assignee: docs@python -> 
components:  -Documentation
nosy: +ncoghlan
type: enhancement -> behavior
versions: +Python 3.7

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue23890>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to