New submission from Julian Berman <[email protected]>:
The following code succeeds "silently", which seems undesirable:
from inspect import signature
def two():
return 2
bound = signature(two).bind()
bound.arguments["does_not_exist"] = 12
two(*bound.args, **bound.kwargs)
where the mechanism for finally calling `two` is the recommended way shown in
the docs for `inspect.BoundArguments`:
https://docs.python.org/3/library/inspect.html#inspect.BoundArguments.apply_defaults
What's happened there is that:
print(b.args, b.kwargs)
"silently" ignored the non-existent argument.
Somewhere along the line here it seems like something should complain. I don't
see previous discussion of this from quickly searching on the bug tracker, but
obviously if I've missed something let me know.
I'm also not really sure what the desirable solution is. To me, it's possibly
that BoundArguments should have a fully-managed way to invoke a callable rather
than asking a user to unpack *args and *kwargs, and that that mechanism, say
arguments.be_passed_to(callable) should do the error checking). Having
`.arguments` full-on reject unknown parameters seems like another possibility
but there may be reasons that's not a good idea (e.g. if you were to for some
reason use a bound arguments object to call some other function that *did* take
that additional argument).
----------
components: Library (Lib)
messages: 376578
nosy: Julian
priority: normal
severity: normal
status: open
title: BoundArguments.arguments used in the recommended way to call a callable
silently succeeds for nonexistent arguments
type: behavior
versions: Python 3.10, Python 3.8, Python 3.9
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue41745>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com