turbosnake/_hooks.py
def use_function_hook(hook_class, arg_1=_sentinel, *args, **kwargs):
    """Generic method for hooks that accept a function as one of arguments.

    Resulting hook can be used as a plain function or as a decorator:

    def use_my_hook(*args):
        return use_function_hook(HookCls, *args)

    ...
    # The following two are equivalent:

    use_my_hook(lambda x: ..., y, z)

    # WARNING: the first argument here MUST NOT be a callable!
    @use_my_hook(y, z)
    def fn(x):
        ...

    # For cases without arguments

    @use_my_hook
    def fn0(x):
        ...
    """
    ctx = ComponentHookProcessor.current()

    if callable(arg_1):
        return ctx.process_hook(hook_class, arg_1, *args, **kwargs)

    def use_function_hook_decorator(fn):
        assert callable(fn)

        return ctx.process_hook(hook_class, fn, *(() if arg_1 is _sentinel else (arg_1,)), *args, **kwargs)

    return use_function_hook_decorator
Generic method for hooks that accept a function as one of arguments.

    Resulting hook can be used as a plain function or as a decorator:

    def use_my_hook(*args):
        return use_function_hook(HookCls, *args)

    ...
    # The following two are equivalent:

    use_my_hook(lambda x: ..., y, z)

    # WARNING: the first argument here MUST NOT be a callable!
    @use_my_hook(y, z)
    def fn(x):
        ...

    # For cases without arguments

    @use_my_hook
    def fn0(x):
        ...
    
Generic method for hooks that accept a function as one of arguments.
Resulting hook can be used as a plain function or as a decorator.



The following two are equivalent.



the first argument here MUST NOT be a callable.

For cases without arguments


Generic method for hooks that accept a function as one of arguments . Resulting hook can be used as a plain function or as a decorator . The following two are equivalent . the first argument here MUST NOT be a callable . For cases without arguments
def use_function_hook(hook_class, arg_1=_sentinel, *args, **kwargs):
    ctx = ComponentHookProcessor.current()
    if callable(arg_1):
        return ctx.process_hook(hook_class, arg_1, *args, **kwargs)
    def use_function_hook_decorator(fn):
        assert callable(fn)
        return ctx.process_hook(hook_class, fn, *(() if arg_1 is _sentinel else (arg_1,)), *args, **kwargs)
    return use_function_hook_decorator
def use_function_hook ( hook_class , arg_1 = _sentinel , * args , ** kwargs ) : ctx = ComponentHookProcessor . current ( ) if callable ( arg_1 ) : return ctx . process_hook ( hook_class , arg_1 , * args , ** kwargs ) def use_function_hook_decorator ( fn ) : assert callable ( fn ) return ctx . process_hook ( hook_class , fn , * ( ( ) if arg_1 is _sentinel else ( arg_1 , ) ) , * args , ** kwargs ) return use_function_hook_decorator
Generic method for hooks that accept a function as one of arguments.
Generic method for hooks that accept a function as one of arguments .
"""Generic method for hooks that accept a function as one of arguments.

    Resulting hook can be used as a plain function or as a decorator:

    def use_my_hook(*args):
        return use_function_hook(HookCls, *args)

    ...
    # The following two are equivalent:

    use_my_hook(lambda x: ..., y, z)

    # WARNING: the first argument here MUST NOT be a callable!
    @use_my_hook(y, z)
    def fn(x):
        ...

    # For cases without arguments

    @use_my_hook
    def fn0(x):
        ...
    """
hook_class
arg_1