def boundmethod(func, callback=None):
"""
Return a weakly-bound instance method from the given bound method. If
callback is provided and not None, the callback will be called when the
referenced object (the method's self) is about to be finalized; the weakly-
bound instance method will be passed to the callback.
If func is already a weakly-bound instance method, return a new weakly-
bound instance method to the underlying bound method.
"""
if inspect.ismethod(func):
return WeakBoundMethod(func, callback)
elif isinstance(func, bound_notification):
return WeakNotification(func, callback)
elif isinstance(func, _WeakCallable):
return boundmethod(getref(func), callback)
else:
raise TypeError("can not create weakly-bound method from '%s' object" % (type(func).__name__,))
评论列表
文章目录