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)
| 847 | return _c3_mro(cls, abcs=mro) |
| 848 | |
| 849 | def _find_impl(cls, registry): |
| 850 | """Returns the best matching implementation from *registry* for type *cls*. |
| 851 | |
| 852 | Where there is no registered implementation for a specific type, its method |
| 853 | resolution order is used to find a more generic implementation. |
| 854 | |
| 855 | Note: if *registry* does not contain an implementation for the base |
| 856 | *object* type, this function may return None. |
| 857 | |
| 858 | """ |
| 859 | mro = _compose_mro(cls, registry.keys()) |
| 860 | match = None |
| 861 | for t in mro: |
| 862 | if match is not None: |
| 863 | # If *match* is an implicit ABC but there is another unrelated, |
| 864 | # equally matching implicit ABC, refuse the temptation to guess. |
| 865 | if (t in registry and t not in cls.__mro__ |
| 866 | and match not in cls.__mro__ |
| 867 | and not issubclass(match, t)): |
| 868 | raise RuntimeError("Ambiguous dispatch: {} or {}".format( |
| 869 | match, t)) |
| 870 | break |
| 871 | if t in registry: |
| 872 | match = t |
| 873 | return registry.get(match) |
| 874 | |
| 875 | def singledispatch(func): |
| 876 | """Single-dispatch generic function decorator. |
no test coverage detected