Get a weak reference to bound or unbound `func`.

    If `func` is unbound (i.e. has no __self__ attr) get a weakref.ref,
    otherwise get a wrapper that simulates weakref.ref.

def get_weakref(func):
    """Get a weak reference to bound or unbound `func`.

    If `func` is unbound (i.e. has no __self__ attr) get a weakref.ref,
    otherwise get a wrapper that simulates weakref.ref.
    """
    if func is None:
        raise ValueError
    if not hasattr(func, '__self__'):
        return weakref.ref(func)
    return WeakMethod(func)