code: def singledispatch(func):
      """Single-dispatch generic function decorator.
  
      Transforms a function into a generic function, which can have different
      behaviours depending upon the type of its first argument. The decorated
      function acts as the default implementation, and additional
      implementations can be registered using the register() attribute of the
      generic function.
      """
      registry = {}
      dispatch_cache = WeakKeyDictionary()
  
      def ns():
          pass
  
      ns.cache_token = None
  
      def dispatch(cls):
          """generic_func.dispatch(cls) -> <function implementation>
  
          Runs the dispatch algorithm to return the best available implementation
          for the given *cls* registered on *generic_func*.
  
          """
          if ns.cache_token is not None:
              current_token = get_cache_token()
              if ns.cache_token != current_token:
                  dispatch_cache.clear()
                  ns.cache_token = current_token
          try:
              impl = dispatch_cache[cls]
          except KeyError:
              try:
                  impl = registry[cls]
              except KeyError:
                  impl = _find_impl(cls, registry)
              dispatch_cache[cls] = impl
          return impl
  
      def register(cls, func=None):
          """generic_func.register(cls, func) -> func
  
          Registers a new implementation for the given *cls* on a *generic_func*.
  
          """
          if func is None:
              if isinstance(cls, type):
                  return lambda f: register(cls, f)
              ann = getattr(cls, "__annotations__", {})
              if not ann:
                  raise TypeError(
                      "Invalid first argument to `register()`: {cls!r}. "
                      "Use either `@register(some_class)` or plain `@register` "
                      "on an annotated function.".format(**locals())
                  )
              func = cls
  
              argname, cls = next(iter(get_type_hints(func).items()))
              if not _validate_annotation(cls):
                  raise TypeError(
                      "Invalid annotation for {argname!r}. "
                      "{cls!r} is not a class.".format(**locals())
                  )
          registry[cls] = func
          if ns.cache_token is None and hasattr(
              cls, "__abstractmethods__"
          ):
              ns.cache_token = get_cache_token()
          dispatch_cache.clear()
          return func
  
      def wrapper(*args, **kw):
          if not args:
              raise TypeError(
                  "{0} requires at least "
                  "1 positional argument".format(funcname)
              )
  
          return dispatch(args[0].__class__)(*args, **kw)
  
      funcname = getattr(func, "__name__", "singledispatch function")
      registry[object] = func
      wrapper.register = register
      wrapper.dispatch = dispatch
      wrapper.registry = MappingProxyType(registry)
      wrapper._clear_cache = dispatch_cache.clear
      update_wrapper(wrapper, func)
      return wrapper
  
file_path: catboost/contrib/deprecated/python/singledispatch/singledispatch/__init__.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from __future__ import unicode_literals
  from weakref import WeakKeyDictionary
  from .helpers import MappingProxyType, get_cache_token, get_type_hints, update_wrapper
label_desc: Use image node_id 7 for calling a global function with example usage: singledispatch(func) and returns: wrapper, impl, func, dispatch, function