cpython
cpython copied to clipboard
gh-87106: Fix `inspect.signature.bind` handling of positional-only arguments with `**kwargs`
gh-87106 Closes #87106
If a function signature has a variadic keyword argument (like **kwargs), then providing a keyword with the same name as a positional-only argument will still succeed, and become available on kwargs.
Before
inspect.signature(f).bind(pos_only='val') might either:
- raise TypeError unnecessarily if the positional-only arg had a default
- raise TypeError with a different flavor of error message than runtime (runtime mentions the missing positional arg, but bind() mentioned the name collision, which wasn't the problem)
Now These are fixed.
Prior related work #16800
:wave: @sobolevn would you be interested to take another look?
Thanks for your suggestions, @sobolevn. Should I move some of the new cases to test_signature_bind_posonly_kwargs()?
Thanks @jacobtylerwalls for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. 🐍🍒⛏🤖
Thanks @jacobtylerwalls for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. 🐍🍒⛏🤖
GH-118984 is a backport of this pull request to the 3.12 branch.
GH-118985 is a backport of this pull request to the 3.13 branch.