generic_func.dispatch(cls) -> Runs the dispatch algorithm to return the best available implementation for the given *cls* registered on *generic_func*.
(cls)
| 912 | cache_token = None |
| 913 | |
| 914 | def dispatch(cls): |
| 915 | """generic_func.dispatch(cls) -> <function implementation> |
| 916 | |
| 917 | Runs the dispatch algorithm to return the best available implementation |
| 918 | for the given *cls* registered on *generic_func*. |
| 919 | |
| 920 | """ |
| 921 | nonlocal cache_token |
| 922 | if cache_token is not None: |
| 923 | current_token = get_cache_token() |
| 924 | if cache_token != current_token: |
| 925 | dispatch_cache.clear() |
| 926 | cache_token = current_token |
| 927 | try: |
| 928 | impl = dispatch_cache[cls] |
| 929 | except KeyError: |
| 930 | try: |
| 931 | impl = registry[cls] |
| 932 | except KeyError: |
| 933 | impl = _find_impl(cls, registry) |
| 934 | dispatch_cache[cls] = impl |
| 935 | return impl |
| 936 | |
| 937 | def _is_valid_dispatch_type(cls): |
| 938 | if isinstance(cls, type): |
no test coverage detected
searching dependent graphs…