[issue41745] BoundArguments.arguments used in the recommended way to call a callable silently succeeds for nonexistent arguments

Terry J. Reedy report at bugs.python.org
Fri Sep 11 20:18:28 EDT 2020


Terry J. Reedy <tjreedy at udel.edu> added the comment:

Bound is created with 5 public attributes:
>>> dir(bound)
[..., 'apply_defaults', 'args', 'arguments', 'kwargs', 'signature']
>>> bound.args
()
>>> bound.arguments
{}
>>> bound.kwargs
{}
msg376578: I don't understand 'non-existent' arguments,  Nor 'what happened...print... ignored' as there is no previous print.

msg376590: Given " Changes in arguments will reflect in args and kwargs.", I agree that changes to 'arguments' *apparently* not being reflected in 'args' and 'kwargs' is initally a bit puzzling
.
>>> bound.kwargs == bound.arguments
True
>>> bound.arguments['something'] = 'guess'
>>> bound.kwargs
{}
>>> bound.arguments
{'something': 'guess'}

However, your 'two' function takes no arguments, so valid values of args and kwargs must be empty for them to be used in a call.  In all cases, args() and kwargs() must look at the signature to see which key-value pairs they should extract from arguments.

>>> def f(a): pass

>>> signature(f).bind()  # Must pass value arguments
Traceback (most recent call last):
...
TypeError: missing a required argument: 'a'
>>> b = signature(f).bind(3)
>>> b.arguments
{'a': 3}
>>> b.args
(3,)  # Because 'a' is positional.
>>> b.kwargs
{}  # Because 'a' is not keyword only.
>>> b.arguments['a']=5
>>> b.args
(5,)  # Legitimate change reflected here.

Perhaps the doc could be improved, but I have no particular suggestion.

----------
assignee:  -> docs at python
components: +Documentation -Library (Lib)
nosy: +docs at python, terry.reedy

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41745>
_______________________________________


More information about the Python-bugs-list mailing list