docstr: Create a dispatched function from a generic backend method.
docstr_tok: ["Create","a","dispatched","function","from","a","generic","backend","method","."]
code: def dispatch_backend_method(cls, name, method):
      """Create a dispatched function from a generic backend method."""
  
      def wrapped_backend_method(*args, **kwargs):
          """A dynamically dispatched method
  
          Returns the queried method from the currently set backend"""
          return getattr(
              cls._THREAD_LOCAL_DATA.__dict__.get(
                  "backend", cls._backend
              ),
              name,
          )(*args, **kwargs)
  
      # We don't use `functools.wraps` here because some of the dispatched
      # methods include the backend (`cls`) as a parameter. Instead we manually
      # copy over the needed information, and filter the signature for `cls`.
      for attr in [
          "__module__",
          "__name__",
          "__qualname__",
          "__doc__",
          "__annotations__",
      ]:
          try:
              setattr(
                  wrapped_backend_method, attr, getattr(method, attr)
              )
          except AttributeError:
              pass
  
      getattr(wrapped_backend_method, "__dict__").update(
          getattr(method, "__dict__", {})
      )
      wrapped_backend_method.__wrapped__ = method
      try:
          sig = inspect.signature(method)
          if "self" in sig.parameters:
              parameters = [
                  v for k, v in sig.parameters.items() if k != "self"
              ]
              sig = sig.replace(parameters=parameters)
          wrapped_backend_method.__signature__ = sig
      except ValueError:
          # If it doesn't have a signature we don't need to remove self
          # This happens for NumPy (e.g. np.where) where inspect.signature(np.where) errors:
          # ValueError: no signature found for builtin <built-in function where>
          pass
  
      return wrapped_backend_method
  
imports: import warnings
  from .core import Backend, backend_array
  import importlib
  import os
  import threading
  from contextlib import contextmanager
  import inspect
  import types
  import sys
label_desc: Use image node_id 6 for calling the BackendManager obj's underlying member method code with example usage: obj.dispatch_backend_method(cls, name, method) and returns: wrapped_backend_method, getattr