def _make_bound_method(func, self):
    """Magic for creating bound methods (used for _unload)."""
    class Foo(object):
        def meth(self): pass
    f = Foo()
    bound_method = type(f.meth)
    try:
        return bound_method(func, self, self.__class__)
    except TypeError: # python3
        return bound_method(func, self)
Magic for creating bound methods (used for _unload).