(func, *positional, **named)
return arg2value
Get the mapping of arguments to values.

    A dict is returned, with keys the function argument names (including the
    names of the * and ** arguments, if any), and values the respective bound
    values from 'positional' and 'named'.
Get the mapping of arguments to values.
Get the mapping of arguments to values .
def getcallargs(func, *positional, **named):
    """Get the mapping of arguments to values.

    A dict is returned, with keys the function argument names (including the
    names of the * and ** arguments, if any), and values the respective bound
    values from 'positional' and 'named'."""
    spec = getfullargspec(func)
    args, varargs, varkw, defaults, kwonlyargs, kwonlydefaults, ann = spec
    f_name = func.__name__
    arg2value = {}

    if ismethod(func) and func.__self__ is not None:
        # implicit 'self' (or 'cls' for classmethods) argument
        positional = (func.__self__,) + positional
    num_pos = len(positional)
    num_total = num_pos + len(named)
    num_args = len(args)
    num_defaults = len(defaults) if defaults else 0
    for arg, value in zip(args, positional):
        arg2value[arg] = value
    if varargs:
        if num_pos > num_args:
            arg2value[varargs] = positional[-(num_pos-num_args):]
        else:
            arg2value[varargs] = ()
    elif 0 < num_args < num_pos:
        raise TypeError('%s() takes %s %d positional %s (%d given)' % (
            f_name, 'at most' if defaults else 'exactly', num_args,
            'arguments' if num_args > 1 else 'argument', num_total))
    elif num_args == 0 and num_total:
        if varkw or kwonlyargs:
            if num_pos:
                # XXX: We should use num_pos, but Python also uses num_total:
                raise TypeError('%s() takes exactly 0 positional arguments '
                                '(%d given)' % (f_name, num_total))
        else:
            raise TypeError('%s() takes no arguments (%d given)' %
                            (f_name, num_total))

    for arg in itertools.chain(args, kwonlyargs):
        if arg in named:
            if arg in arg2value:
                raise TypeError("%s() got multiple values for keyword "
                                "argument '%s'" % (f_name, arg))
            else:
                arg2value[arg] = named.pop(arg)
    for kwonlyarg in kwonlyargs:
        if kwonlyarg not in arg2value:
            try:
                arg2value[kwonlyarg] = kwonlydefaults[kwonlyarg]
            except KeyError:
                raise TypeError("%s() needs keyword-only argument %s" %
                                (f_name, kwonlyarg))
    if defaults:    # fill in any missing values with the defaults
        for arg, value in zip(args[-num_defaults:], defaults):
            if arg not in arg2value:
                arg2value[arg] = value
    if varkw:
        arg2value[varkw] = named
    elif named:
        unexpected = next(iter(named))
        raise TypeError("%s() got an unexpected keyword argument '%s'" %
                        (f_name, unexpected))
    unassigned = num_args - len([arg for arg in args if arg in arg2value])
    if unassigned:
        num_required = num_args - num_defaults
        raise TypeError('%s() takes %s %d %s (%d given)' % (
            f_name, 'at least' if defaults else 'exactly', num_required,
            'arguments' if num_required > 1 else 'argument', num_total))
    return arg2value
def getcallargs ( func , * positional , * * named ) : spec = getfullargspec ( func ) args , varargs , varkw , defaults , kwonlyargs , kwonlydefaults , ann = spec f_name = func . __name__ arg2value = { } if ismethod ( func ) and func . __self__ is not None : # implicit 'self' (or 'cls' for classmethods) argument positional = ( func . __self__ , ) + positional num_pos = len ( positional ) num_total = num_pos + len ( named ) num_args = len ( args ) num_defaults = len ( defaults ) if defaults else 0 for arg , value in zip ( args , positional ) : arg2value [ arg ] = value if varargs : if num_pos > num_args : arg2value [ varargs ] = positional [ - ( num_pos - num_args ) : ] else : arg2value [ varargs ] = ( ) elif 0 < num_args < num_pos : raise TypeError ( '%s() takes %s %d positional %s (%d given)' % ( f_name , 'at most' if defaults else 'exactly' , num_args , 'arguments' if num_args > 1 else 'argument' , num_total ) ) elif num_args == 0 and num_total : if varkw or kwonlyargs : if num_pos : # XXX: We should use num_pos, but Python also uses num_total: raise TypeError ( '%s() takes exactly 0 positional arguments ' '(%d given)' % ( f_name , num_total ) ) else : raise TypeError ( '%s() takes no arguments (%d given)' % ( f_name , num_total ) ) for arg in itertools . chain ( args , kwonlyargs ) : if arg in named : if arg in arg2value : raise TypeError ( "%s() got multiple values for keyword " "argument '%s'" % ( f_name , arg ) ) else : arg2value [ arg ] = named . pop ( arg ) for kwonlyarg in kwonlyargs : if kwonlyarg not in arg2value : try : arg2value [ kwonlyarg ] = kwonlydefaults [ kwonlyarg ] except KeyError : raise TypeError ( "%s() needs keyword-only argument %s" % ( f_name , kwonlyarg ) ) if defaults : # fill in any missing values with the defaults for arg , value in zip ( args [ - num_defaults : ] , defaults ) : if arg not in arg2value : arg2value [ arg ] = value if varkw : arg2value [ varkw ] = named elif named : unexpected = next ( iter ( named ) ) raise TypeError ( "%s() got an unexpected keyword argument '%s'" % ( f_name , unexpected ) ) unassigned = num_args - len ( [ arg for arg in args if arg in arg2value ] ) if unassigned : num_required = num_args - num_defaults raise TypeError ( '%s() takes %s %d %s (%d given)' % ( f_name , 'at least' if defaults else 'exactly' , num_required , 'arguments' if num_required > 1 else 'argument' , num_total ) ) return arg2value