An implementation of weak references that works for bound methods.
This code is based on the code in the Python Cookbook, but you can call ref for objects that are not bound methods too, in which case it just returns a standard weakref.ref.
Weak references to bound methods are cached so that ref(x) is ref(x) as for standard weakrefs, and the ref class defined here is therefore intended to be used as a drop-in replacement for ‘weakref.ref’.
An implementation of weak references that works for bound methods and caches them.
objectis a bound method, returns a
weakref.WeakMethodfor that method. This ensures that the method is kept alive for the lifetime of the object that it’s bound to.
For any other
object, a normal
Deprecated since version 5.0.0.