Weak Method Reference

Provides an implementation of a WeakMethodReference for weak references to functions and methods.

The standard weakref module in Python cannot store references to non-bound functions and should not be used to perform this task.

Code borrowed from the following places: http://code.activestate.com/recipes/81253/ http://stackoverflow.com/questions/3942303/how-does-a-python-set-check-if-two-objects-are-equal-what-methods-does-an-o

class pygly.weak_method_reference.WeakMethodReference(function=None)[source]

Provides the ability to store a weak pointer to class members on top of the existing weakref functionality provided by python.

This class also provides comparison operators to allow proper usage in containers such as set([]).

The ability to change the weak reference is not supported to prevent mutability. This is important for container support as the object hash would change after storing it.


Initialises the weak reference with a function or class method.

function: The object to store a weak reference to. This can be a class, object, method or function.

Check if the referenced object is valid.

The equivalent to ‘not is_dead()’ Make a positive method call because double negatives suck


Check if the referenced object is invalid.

True if the referenced callable was a bound method and the instance no longer exists. Otherwise, return False.