[issue45555] Object stays alive for weak reference if an exception happens in constructor

Pablo Galindo Salgado report at bugs.python.org
Fri Oct 22 10:52:17 EDT 2021


Pablo Galindo Salgado <pablogsal at gmail.com> added the comment:

I concur, this is not a bug. The contract of the weakref is that the callback will be triggered when the object is destroyed, but here the object is not destroyed because is owned by the frame in the traceback.

As Mark correctly mentions, the object should die when the try/except/finally ends.

I am not sure if it makes sense to document this because this does not really relate to weak reference, but why an object is alive. This is by far not the only weird way that can keep the object alive and maintain the behaviour so I don't know if it makes sense to document this because there are many many other confusing scenarios.

For now, I am marking this as "not a bug" but keeping it open in case we want to improve the docs.

----------
resolution:  -> not a bug

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45555>
_______________________________________


More information about the Python-bugs-list mailing list