import inspect


def func_args_to_dict(func, args):
    """
    Make the arguments of function to a named dict

    Examples:

    from damson.support import func_args_to_dict

    def wrapper(fn):
        def func(*args,**kwargs):
            named_args=func_args_to_dict(fn,args)
            print(named_args)

            return fn(*args,**kwargs)
        return func

    @wrapper
    def add(a,b):
       return a+b



    :param func: A instance of function
    :param args: the arguments
    :return: a named argument dict
    """
    if not inspect.isfunction(func) or not isinstance(args, (list, tuple)):
        raise ValueError()
    varnames = func.__code__.co_varnames
    kvmap = {}
    for index, varname in enumerate(varnames):
        if index < len(args):
            kvmap[varname] = args[index]
    return kvmap
