class WeakBoundMethod:
I suggest making it a new-style class by inheriting from object.
assert (hasattr(meth, '__func__') and hasattr(meth, '__self__')),\
'Object is not a bound method.'
Don't do this. Just let the invalid parameter types raise attribute errors when you try to fetch the __func__
and __self__
. You don't gain anything by checking them beforehand.
assert self.alive(), 'Bound method called on deleted object.'
Raising an Assertion here is a bad choice. Assertions are for thing that should never happen, but having the underlying self object cleaned up doesn't really count. Raise an exception like weakref.ReferenceError. That way a caller can reasonably catch the error.
The documentation is very clear, well done.