parameters: (func, ignore_lst, args=(), kwargs=dict())
return_statement: return arg_dict
docstring: Filters the given args and kwargs using a list of arguments to
          ignore, and a function specification.
  
          Parameters
          ----------
          func: callable
              Function giving the argument specification
          ignore_lst: list of strings
              List of arguments to ignore (either a name of an argument
              in the function spec, or '*', or '**')
          *args: list
              Positional arguments passed to the function.
          **kwargs: dict
              Keyword arguments passed to the function
  
          Returns
          -------
          filtered_args: list
              List of filtered positional and keyword arguments.
docstring_summary: Filters the given args and kwargs using a list of arguments to
          ignore, and a function specification.
docstring_tokens: Filters the given args and kwargs using a list of arguments to ignore and a function specification .
function: def filter_args(func, ignore_lst, args=(), kwargs=dict()):
      """ Filters the given args and kwargs using a list of arguments to
          ignore, and a function specification.
  
          Parameters
          ----------
          func: callable
              Function giving the argument specification
          ignore_lst: list of strings
              List of arguments to ignore (either a name of an argument
              in the function spec, or '*', or '**')
          *args: list
              Positional arguments passed to the function.
          **kwargs: dict
              Keyword arguments passed to the function
  
          Returns
          -------
          filtered_args: list
              List of filtered positional and keyword arguments.
      """
      args = list(args)
      if isinstance(ignore_lst, str):
          # Catch a common mistake
          raise ValueError(
              'ignore_lst must be a list of parameters to ignore '
              '%s (type %s) was given' % (ignore_lst, type(ignore_lst)))
      # Special case for functools.partial objects
      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_sig = inspect.signature(func)
      arg_names = []
      arg_defaults = []
      arg_kwonlyargs = []
      arg_varargs = None
      arg_varkw = None
      for param in arg_sig.parameters.values():
          if param.kind is param.POSITIONAL_OR_KEYWORD:
              arg_names.append(param.name)
          elif param.kind is param.KEYWORD_ONLY:
              arg_names.append(param.name)
              arg_kwonlyargs.append(param.name)
          elif param.kind is param.VAR_POSITIONAL:
              arg_varargs = param.name
          elif param.kind is param.VAR_KEYWORD:
              arg_varkw = param.name
          if param.default is not param.empty:
              arg_defaults.append(param.default)
      if inspect.ismethod(func):
          # First argument is 'self', it has been removed by Python
          # we need to add it back:
          args = [func.__self__, ] + args
          # func is an instance method, inspect.signature(func) does not
          # include self, we need to fetch it from the class method, i.e
          # func.__func__
          class_method_sig = inspect.signature(func.__func__)
          self_name = next(iter(class_method_sig.parameters))
          arg_names = [self_name] + arg_names
      # XXX: Maybe I need an inspect.isbuiltin to detect C-level methods, such
      # as on ndarrays.
  
      _, 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):
              # Positional argument or keyword argument given as positional
              if arg_name not in arg_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_sig),
                         _function_called_str(name, args, kwargs))
                  )
  
          else:
              position = arg_position - len(arg_names)
              if arg_name in kwargs:
                  arg_dict[arg_name] = kwargs[arg_name]
              else:
                  try:
                      arg_dict[arg_name] = arg_defaults[position]
                  except (IndexError, KeyError) as e:
                      # Missing argument
                      raise ValueError(
                          'Wrong number of arguments for %s:\n'
                          '     %s was called.'
                          % (_signature_str(name, arg_sig),
                             _function_called_str(name, args, kwargs))
                      ) from e
  
      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
  
      # Now remove the arguments to be ignored
      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_sig))
                               )
      # XXX: Return a sorted list of pairs?
      return arg_dict
function_tokens: def filter_args ( func , ignore_lst , args = ( ) , kwargs = dict ( ) ) : args = list ( args ) if isinstance ( ignore_lst , str ) : # Catch a common mistake raise ValueError ( 'ignore_lst must be a list of parameters to ignore ' '%s (type %s) was given' % ( ignore_lst , type ( ignore_lst ) ) ) # Special case for functools.partial objects 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_sig = inspect . signature ( func ) arg_names = [ ] arg_defaults = [ ] arg_kwonlyargs = [ ] arg_varargs = None arg_varkw = None for param in arg_sig . parameters . values ( ) : if param . kind is param . POSITIONAL_OR_KEYWORD : arg_names . append ( param . name ) elif param . kind is param . KEYWORD_ONLY : arg_names . append ( param . name ) arg_kwonlyargs . append ( param . name ) elif param . kind is param . VAR_POSITIONAL : arg_varargs = param . name elif param . kind is param . VAR_KEYWORD : arg_varkw = param . name if param . default is not param . empty : arg_defaults . append ( param . default ) if inspect . ismethod ( func ) : # First argument is 'self', it has been removed by Python # we need to add it back: args = [ func . __self__ , ] + args # func is an instance method, inspect.signature(func) does not # include self, we need to fetch it from the class method, i.e # func.__func__ class_method_sig = inspect . signature ( func . __func__ ) self_name = next ( iter ( class_method_sig . parameters ) ) arg_names = [ self_name ] + arg_names # XXX: Maybe I need an inspect.isbuiltin to detect C-level methods, such # as on ndarrays. _ , 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 ) : # Positional argument or keyword argument given as positional if arg_name not in arg_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_sig ) , _function_called_str ( name , args , kwargs ) ) ) else : position = arg_position - len ( arg_names ) if arg_name in kwargs : arg_dict [ arg_name ] = kwargs [ arg_name ] else : try : arg_dict [ arg_name ] = arg_defaults [ position ] except ( IndexError , KeyError ) as e : # Missing argument raise ValueError ( 'Wrong number of arguments for %s:\n' '     %s was called.' % ( _signature_str ( name , arg_sig ) , _function_called_str ( name , args , kwargs ) ) ) from e 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 # Now remove the arguments to be ignored 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_sig ) ) ) # XXX: Return a sorted list of pairs? return arg_dict