Is there any obstacle that prevents weakref
from doing everything that __del__
does but with much stronger guarantees (e.g., finalize
guarantees that the call will be made before the interpreter exits, and the order of calls is well-defined, etc.)?
It seems that in the distant past it was thought that weakref
would eventually lead to the removal of __del__
from the language.
What prevented this from happening?
There seems to be few use cases for __del__
, and all the ones I'm aware of seem to work at least as well (and usually much better) with weakref
callbacks or weakref.finalize
.
Update:
With PEP 442 dramatically improving the behavior of __del__
, and the concerns with weakref
mentioned by @gz and @user2357112, I'm wondering if the language is generally moving towards making __del__
more reliable, or towards using weakref
instead of __del__
, or both.