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

Function _find_impl

Lib/functools.py:870–894  ·  view source on GitHub ↗

Returns the best matching implementation from *registry* for type *cls*. Where there is no registered implementation for a specific type, its method resolution order is used to find a more generic implementation. Note: if *registry* does not contain an implementation for the base *

(cls, registry)

Source from the content-addressed store, hash-verified

868 return _c3_mro(cls, abcs=mro)
869
870def _find_impl(cls, registry):
871 """Returns the best matching implementation from *registry* for type *cls*.
872
873 Where there is no registered implementation for a specific type, its method
874 resolution order is used to find a more generic implementation.
875
876 Note: if *registry* does not contain an implementation for the base
877 *object* type, this function may return None.
878
879 """
880 mro = _compose_mro(cls, registry.keys())
881 match = None
882 for t in mro:
883 if match is not None:
884 # If *match* is an implicit ABC but there is another unrelated,
885 # equally matching implicit ABC, refuse the temptation to guess.
886 if (t in registry and t not in cls.__mro__
887 and match not in cls.__mro__
888 and not issubclass(match, t)):
889 raise RuntimeError("Ambiguous dispatch: {} or {}".format(
890 match, t))
891 break
892 if t in registry:
893 match = t
894 return registry.get(match)
895
896def singledispatch(func):
897 """Single-dispatch generic function decorator.

Callers 1

dispatchFunction · 0.85

Calls 4

_compose_mroFunction · 0.85
keysMethod · 0.45
formatMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…