def METHOD_NAME(target, on_delete=None):
    """Return a *safe* weak reference to a callable target.
    - ``target``: The object to be weakly referenced, if it's a bound
      method reference, will create a BoundMethodWeakref, otherwise
      creates a simple weakref.
    - ``on_delete``: If provided, will have a hard reference stored to
      the callable to be called after the safe reference goes out of
      scope with the reference object, (either a weakref or a
      BoundMethodWeakref) as argument.
    """
    if hasattr(target, "im_self"):
        if target.__self__ is not None:
            # Turn a bound method into a BoundMethodWeakref instance.
            # Keep track of these instances for lookup by disconnect().
            assert hasattr(target, "im_func"), (
                "safe_ref target %r has im_self, but no im_func, "
                "don't know how to create reference" % target
            )
            reference = BoundMethodWeakref(target=target, on_delete=on_delete)
            return reference
    if isinstance(on_delete, collections.abc.Callable):
        return weakref.ref(target, on_delete)
    else:
        return weakref.ref(target)