dialogue/multi_method/__init__.py
def multi(dispatch_fn, default=None):
    """A decorator for a function to dispatch on.

    The value returned by the dispatch function is used to look up the
    implementation function based on its dispatch key.

    The dispatch function is available using the `dispatch_fn` function.
    """

    def _inner(*args, **kwargs):
        dispatch_value = dispatch_fn(*args, **kwargs)
        f = _inner.__multi__.get(dispatch_value, _inner.__multi_default__)
        if f is None:
            raise Exception(
                f"No implementation of {dispatch_fn.__name__} "
                f"for dispatch value {dispatch_value}"
            )
        return f(*args, **kwargs)

    _inner.__multi__ = {}
    _inner.__multi_default__ = default
    _inner.__dispatch_fn__ = dispatch_fn
    return _inner
def multi(dispatch_fn, default=None):
    """A decorator for a function to dispatch on.

    The value returned by the dispatch function is used to look up the
    implementation function based on its dispatch key.

    The dispatch function is available using the `dispatch_fn` function.
    """

    def _inner(*args, **kwargs):
        dispatch_value = dispatch_fn(*args, **kwargs)
        f = _inner.__multi__.get(dispatch_value, _inner.__multi_default__)
        if f is None:
            raise Exception(
                f"No implementation of {dispatch_fn.__name__} "
                f"for dispatch value {dispatch_value}"
            )
        return f(*args, **kwargs)

    _inner.__multi__ = {}
    _inner.__multi_default__ = default
    _inner.__dispatch_fn__ = dispatch_fn
    return _inner
A decorator for a function to dispatch on.

    The value returned by the dispatch function is used to look up the
    implementation function based on its dispatch key.

    The dispatch function is available using the `dispatch_fn` function.