MCPcopy Index your code
hub / github.com/python/cpython / dispatch

Function dispatch

Lib/functools.py:914–935  ·  view source on GitHub ↗

generic_func.dispatch(cls) -> Runs the dispatch algorithm to return the best available implementation for the given *cls* registered on *generic_func*.

(cls)

Source from the content-addressed store, hash-verified

912 cache_token = None
913
914 def dispatch(cls):
915 """generic_func.dispatch(cls) -> <function implementation>
916
917 Runs the dispatch algorithm to return the best available implementation
918 for the given *cls* registered on *generic_func*.
919
920 """
921 nonlocal cache_token
922 if cache_token is not None:
923 current_token = get_cache_token()
924 if cache_token != current_token:
925 dispatch_cache.clear()
926 cache_token = current_token
927 try:
928 impl = dispatch_cache[cls]
929 except KeyError:
930 try:
931 impl = registry[cls]
932 except KeyError:
933 impl = _find_impl(cls, registry)
934 dispatch_cache[cls] = impl
935 return impl
936
937 def _is_valid_dispatch_type(cls):
938 if isinstance(cls, type):

Callers 1

wrapperFunction · 0.70

Calls 3

get_cache_tokenFunction · 0.90
_find_implFunction · 0.85
clearMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…