generic_func.dispatch(cls) -> Runs the dispatch algorithm to return the best available implementation for the given *cls* registered on *generic_func*.
(cls)
| 816 | cache_token = None |
| 817 | |
| 818 | def dispatch(cls): |
| 819 | """generic_func.dispatch(cls) -> <function implementation> |
| 820 | |
| 821 | Runs the dispatch algorithm to return the best available implementation |
| 822 | for the given *cls* registered on *generic_func*. |
| 823 | |
| 824 | """ |
| 825 | nonlocal cache_token |
| 826 | if cache_token is not None: |
| 827 | current_token = get_cache_token() |
| 828 | if cache_token != current_token: |
| 829 | dispatch_cache.clear() |
| 830 | cache_token = current_token |
| 831 | try: |
| 832 | impl = dispatch_cache[cls] |
| 833 | except KeyError: |
| 834 | try: |
| 835 | impl = registry[cls] |
| 836 | except KeyError: |
| 837 | impl = _find_impl(cls, registry) |
| 838 | dispatch_cache[cls] = impl |
| 839 | return impl |
| 840 | |
| 841 | def _is_union_type(cls): |
| 842 | from typing import get_origin, Union |
no test coverage detected