Author Julian
Recipients Julian
Date 2020-09-08.15:40:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1599579646.4.0.421271904228.issue41745@roundup.psfhosted.org>
In-reply-to
Content
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).
History
Date User Action Args
2020-09-08 15:40:46Juliansetrecipients: + Julian
2020-09-08 15:40:46Juliansetmessageid: <1599579646.4.0.421271904228.issue41745@roundup.psfhosted.org>
2020-09-08 15:40:46Julianlinkissue41745 messages
2020-09-08 15:40:46Juliancreate