Python functools._find_impl() Examples

The following are 3 code examples of functools._find_impl(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module functools , or try the search function .
Example #1
Source File: decorators.py    From eventsourcing with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def applicationpolicy2(arg: Callable) -> Callable:
    """
    This one doesn't use weakrefs.
    """
    handlers = {}
    cache = {}

    def _mutator(func):
        def dispatch(event_type):
            try:
                return cache[event_type]
            except KeyError:
                handler = _find_impl(event_type, handlers) or func
                cache[event_type] = handler
                return handler

        @wraps(func)
        def policy_function_wrapper(*args, **kwargs):
            event = kwargs.get("event") or args[-1]
            return dispatch(type(event))(*args, **kwargs)

        def register(event_type):
            def registered_function_decorator(func):
                handlers[event_type] = func
                return func

            return registered_function_decorator

        policy_function_wrapper.register = register

        return policy_function_wrapper

    return _mutator(arg) 
Example #2
Source File: h5ad.py    From anndata with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _write_method(cls: Type[T]) -> Callable[[H5Group, str, T], None]:
    return _find_impl(cls, H5AD_WRITE_REGISTRY) 
Example #3
Source File: zarr.py    From anndata with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def _write_method(cls: Type[T]) -> Callable[[zarr.Group, str, T], None]:
    return _find_impl(cls, ZARR_WRITE_REGISTRY)