def args_from_config(func):
    """Decorator that injects parameters from the configuration.
    """
    func_args = signature(func).parameters

    @wraps(func)
    def wrapper(*args, **kwargs):
        config = get_config()
        for i, argname in enumerate(func_args):
            if len(args) > i or argname in kwargs:
                continue
            elif argname in config:
                kwargs[argname] = config[argname]
        try:
            getcallargs(func, *args, **kwargs)
        except TypeError as exc:
            msg = "{}\n{}".format(exc.args[0], PALLADIUM_CONFIG_ERROR)
            exc.args = (msg,)
            raise exc
        return func(*args, **kwargs)

    wrapper.__wrapped__ = func
    return wrapper
def args_from_config ( func ) : func_args = signature ( func ) . parameters @ wraps ( func ) def wrapper ( * args , ** kwargs ) : config = get_config ( ) for i , argname in enumerate ( func_args ) : if len ( args ) > i or argname in kwargs : continue elif argname in config : kwargs [ argname ] = config [ argname ] try : getcallargs ( func , * args , ** kwargs ) except TypeError as exc : msg = "{}\n{}" . format ( exc . args [ 0 ] , PALLADIUM_CONFIG_ERROR ) exc . args = ( msg , ) raise exc return func ( * args , ** kwargs ) wrapper . __wrapped__ = func return wrapper
Decorator that injects parameters from the configuration.