envisage.safeweakref module

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’.

class envisage.safeweakref.ref[source]

Bases: object

An implementation of weak references that works for bound methods and caches them.

If object is a bound method, returns a weakref.WeakMethod for 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 weakref.ref is returned.

Deprecated since version 5.0.0.