MCPcopy Index your code
hub / github.com/dask/dask / Dispatch

Class Dispatch

dask/utils.py:710–790  ·  view source on GitHub ↗

Simple single dispatch.

Source from the content-addressed store, hash-verified

708
709
710class Dispatch:
711 """Simple single dispatch."""
712
713 def __init__(self, name=None):
714 self._lookup = {}
715 self._lazy = {}
716 if name:
717 self.__name__ = name
718
719 def register(self, type, func=None):
720 """Register dispatch of `func` on arguments of type `type`"""
721
722 def wrapper(func):
723 if isinstance(type, tuple):
724 for t in type:
725 self.register(t, func)
726 else:
727 self._lookup[type] = func
728 return func
729
730 return wrapper(func) if func is not None else wrapper
731
732 def register_lazy(self, toplevel, func=None):
733 """
734 Register a registration function which will be called if the
735 *toplevel* module (e.g. 'pandas') is ever loaded.
736 """
737
738 def wrapper(func):
739 self._lazy[toplevel] = func
740 return func
741
742 return wrapper(func) if func is not None else wrapper
743
744 def dispatch(self, cls):
745 """Return the function implementation for the given ``cls``"""
746 lk = self._lookup
747 if cls in lk:
748 return lk[cls]
749 for cls2 in cls.__mro__:
750 # Is a lazy registration function present?
751 try:
752 toplevel, _, _ = cls2.__module__.partition(".")
753 except Exception:
754 continue
755 try:
756 register = self._lazy[toplevel]
757 except KeyError:
758 pass
759 else:
760 register()
761 self._lazy.pop(toplevel, None)
762 meth = self.dispatch(cls) # recurse
763 lk[cls] = meth
764 lk[cls2] = meth
765 return meth
766 try:
767 impl = lk[cls2]

Callers 11

_dispatch.pyFile · 0.90
sizeof.pyFile · 0.90
tokenize.pyFile · 0.90
extensions.pyFile · 0.90
dispatch.pyFile · 0.90
test_dispatchFunction · 0.90
test_dispatch_kwargsFunction · 0.90
test_dispatch_lazyFunction · 0.90
dispatch.pyFile · 0.90

Calls

no outgoing calls

Tested by 5

test_dispatchFunction · 0.72
test_dispatch_kwargsFunction · 0.72
test_dispatch_lazyFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…