def get_weak_reference(f):
    """
    Returns a WeakMethodFree or a WeakMethodBound for the supplied function, as
    appropriate
    """
    try:
        f.im_func
    except AttributeError:
        return WeakMethodFree(f)
    return WeakMethodBound(f)