class inspect.BoundArguments
Result of a Signature.bind() or Signature.bind_partial() call. Holds the mapping of arguments to the function’s parameters.
-
arguments -
An ordered, mutable mapping (
collections.OrderedDict) of parameters’ names to arguments’ values. Contains only explicitly bound arguments. Changes inargumentswill reflect inargsandkwargs.Should be used in conjunction with
Signature.parametersfor any argument processing purposes.Note
Arguments for which
Signature.bind()orSignature.bind_partial()relied on a default value are skipped. However, if needed, useBoundArguments.apply_defaults()to add them.
-
args -
A tuple of positional arguments values. Dynamically computed from the
argumentsattribute.
-
kwargs -
A dict of keyword arguments values. Dynamically computed from the
argumentsattribute.
-
signature -
A reference to the parent
Signatureobject.
-
apply_defaults() -
Set default values for missing arguments.
For variable-positional arguments (
*args) the default is an empty tuple.For variable-keyword arguments (
**kwargs) the default is an empty dict.>>> def foo(a, b='ham', *args): pass >>> ba = inspect.signature(foo).bind('spam') >>> ba.apply_defaults() >>> ba.arguments OrderedDict([('a', 'spam'), ('b', 'ham'), ('args', ())])New in version 3.5.
The args and kwargs properties can be used to invoke functions:
def test(a, *, b):
...
sig = signature(test)
ba = sig.bind(10, b=20)
test(*ba.args, **ba.kwargs)
Please login to continue.