MCPcopy Index your code
hub / github.com/RustPython/RustPython / dispatch

Function dispatch

Lib/functools.py:893–914  ·  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

891 cache_token = None
892
893 def dispatch(cls):
894 """generic_func.dispatch(cls) -> <function implementation>
895
896 Runs the dispatch algorithm to return the best available implementation
897 for the given *cls* registered on *generic_func*.
898
899 """
900 nonlocal cache_token
901 if cache_token is not None:
902 current_token = get_cache_token()
903 if cache_token != current_token:
904 dispatch_cache.clear()
905 cache_token = current_token
906 try:
907 impl = dispatch_cache[cls]
908 except KeyError:
909 try:
910 impl = registry[cls]
911 except KeyError:
912 impl = _find_impl(cls, registry)
913 dispatch_cache[cls] = impl
914 return impl
915
916 def _is_valid_dispatch_type(cls):
917 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