generic_func.dispatch(cls) -> Runs the dispatch algorithm to return the best available implementation for the given *cls* registered on *generic_func*.
(cls)
| 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): |
no test coverage detected