

def filter_args(func, ignore_lst, args=(), kwargs=dict()):
    " Filters the given args and kwargs using a list of arguments to\n        ignore, and a function specification.\n\n        Parameters\n        ----------\n        func: callable\n            Function giving the argument specification\n        ignore_lst: list of strings\n            List of arguments to ignore (either a name of an argument\n            in the function spec, or '*', or '**')\n        *args: list\n            Positional arguments passed to the function.\n        **kwargs: dict\n            Keyword arguments passed to the function\n\n        Returns\n        -------\n        filtered_args: list\n            List of filtered positional and keyword arguments.\n    "
    args = list(args)
    if isinstance(ignore_lst, _basestring):
        raise ValueError(('ignore_lst must be a list of parameters to ignore %s (type %s) was given' % (ignore_lst, type(ignore_lst))))
    if ((not inspect.ismethod(func)) and (not inspect.isfunction(func))):
        if ignore_lst:
            warnings.warn(('Cannot inspect object %s, ignore list will not work.' % func), stacklevel=2)
        return {
            '*': args,
            '**': kwargs,
        }
    arg_spec = getfullargspec(func)
    arg_names = (arg_spec.args + arg_spec.kwonlyargs)
    arg_defaults = (arg_spec.defaults or ())
    arg_defaults = (arg_defaults + tuple((arg_spec.kwonlydefaults[func] for k in arg_spec.kwonlyargs)))
    arg_varargs = arg_spec.varargs
    arg_varkw = arg_spec.varkw
    if inspect.ismethod(func):
        args = ([func.__self__] + args)
    (_, name) = get_func_name(func, resolv_alias=False)
    arg_dict = dict()
    arg_position = (- 1)
    for (arg_position, arg_name) in enumerate(arg_names):
        if (arg_position < len(args)):
            if (arg_name not in arg_spec.kwonlyargs):
                arg_dict[arg_name] = args[arg_position]
            else:
                raise ValueError(("Keyword-only parameter '%s' was passed as positional parameter for %s:\n     %s was called." % (arg_name, _signature_str(name, arg_spec), _function_called_str(name, args, kwargs))))
        else:
            position = (arg_position - len(arg_names))
            if (arg_name in kwargs):
                arg_dict[arg_name] = kwargs.pop(arg_name)
            else:
                try:
                    arg_dict[arg_name] = arg_defaults[position]
                except (IndexError, KeyError):
                    raise ValueError(('Wrong number of arguments for %s:\n     %s was called.' % (_signature_str(name, arg_spec), _function_called_str(name, args, kwargs))))
    varkwargs = dict()
    for (arg_name, arg_value) in sorted(kwargs.items()):
        if (arg_name in arg_dict):
            arg_dict[arg_name] = arg_value
        elif (arg_varkw is not None):
            varkwargs[arg_name] = arg_value
        else:
            raise TypeError(("Ignore list for %s() contains an unexpected keyword argument '%s'" % (name, arg_name)))
    if (arg_varkw is not None):
        arg_dict['**'] = varkwargs
    if (arg_varargs is not None):
        varargs = args[(arg_position + 1):]
        arg_dict['*'] = varargs
    for item in ignore_lst:
        if (item in arg_dict):
            arg_dict.pop(item)
        else:
            raise ValueError(("Ignore list: argument '%s' is not defined for function %s" % (item, _signature_str(name, arg_spec))))
    return arg_dict

dataset/ETHPy150Open scikit-learn/scikit-learn/sklearn/externals/joblib/func_inspect.py filter_args/VarMisuse@164/473 `k`->`func`