code: def get_weakref(func):
      
      if func is None:
          raise ValueError
      if not hasattr(func, '__self__'):
          return weakref.ref(func)
      return WeakMethod(func)
docs: 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.