STINNER Victor added the comment:

It looks like io.FileIO has a strong implementation of the destructor. If the 
object becomes alive again because of random code called in the destructor, the 
object is not removed.

socket and os.scandir have a classical unsafe destructor.

Moreover, I'm no more sure about the chosen design. When 
warnings.catch_warnings() is used and an unclosed io.FileIO is destroyed, the 
object is kept alive because it is stored in the "source" attribute of a 
warnings.WarningMessage.

I don't know if keeping WarningMessaging alive longer than the call to 
showwarning() (or _showarnmsg) is a common use case or not. The issue #26568 
wants to promote the WarningMessage class, so some users may start to keep it 
alive.

An alternative is to format the object traceback and pass the traceback to 
WarningMessage. It requires to decide the format of the traceback (list of ..., 
string, something else?).

----------

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

Reply via email to