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)
| 868 | return _c3_mro(cls, abcs=mro) |
| 869 | |
| 870 | def _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 | |
| 896 | def singledispatch(func): |
| 897 | """Single-dispatch generic function decorator. |
no test coverage detected
searching dependent graphs…