def fold_arguments(pysig, args, kws, normal_handler, default_handler, stararg_handler):
 ba = pysig.bind(*args, **kws)
 defargs = []
 for (i, param) in enumerate(pysig.parameters.values()):
  name = param.name
  default = param.default
  if (param.kind == param.VAR_POSITIONAL):
   ba.arguments[name] = stararg_handler(i, param, ba.arguments.get(name, ()))
  elif (name in ba.arguments):
   ba.arguments[name] = normal_handler(i, param, ba.arguments[name])
  else:
   assert (default is not param.empty)
   ba.arguments[name] = default_handler(i, param, default)
 if ba.kwargs:
  raise NotImplementedError(('unhandled keyword argument: %s' % list(ba.kwargs)))
 args = tuple((ba.arguments[param.name] for param in pysig.parameters.values()))
 return args

def fold_arguments ( pysig , args , kws , normal_handler , default_handler , stararg_handler ) : ba = pysig . bind ( * args , ** kws ) defargs = [ ] for ( i , param ) in enumerate ( pysig . parameters . values ( ) ) : name = param . name default = param . default if ( param . kind == param . VAR_POSITIONAL ) : ba . arguments [ name ] = stararg_handler ( i , param , ba . arguments . get ( name , ( ) ) ) elif ( name in ba . arguments ) : ba . arguments [ name ] = normal_handler ( i , param , ba . arguments [ name ] ) else : assert ( default is not param . empty ) ba . arguments [ name ] = default_handler ( i , param , default ) if ba . kwargs : raise NotImplementedError ( ( 'unhandled keyword argument: %s' % list ( ba . kwargs ) ) ) args = tuple ( ( ba . arguments [ param . name ] for param in pysig . parameters . values ( ) ) ) return args
given the signature *pysig* .