cpython icon indicating copy to clipboard operation
cpython copied to clipboard

gh-87106: Fix `inspect.signature.bind` handling of positional-only arguments with `**kwargs`

Open jacobtylerwalls opened this issue 2 years ago • 2 comments

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

jacobtylerwalls avatar Apr 10 '23 04:04 jacobtylerwalls

:wave: @sobolevn would you be interested to take another look?

jacobtylerwalls avatar May 04 '24 23:05 jacobtylerwalls

Thanks for your suggestions, @sobolevn. Should I move some of the new cases to test_signature_bind_posonly_kwargs()?

jacobtylerwalls avatar May 05 '24 15:05 jacobtylerwalls

Thanks @jacobtylerwalls for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. 🐍🍒⛏🤖

miss-islington-app[bot] avatar May 13 '24 07:05 miss-islington-app[bot]

Thanks @jacobtylerwalls for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. 🐍🍒⛏🤖

miss-islington-app[bot] avatar May 13 '24 07:05 miss-islington-app[bot]

GH-118984 is a backport of this pull request to the 3.12 branch.

bedevere-app[bot] avatar May 13 '24 07:05 bedevere-app[bot]

GH-118985 is a backport of this pull request to the 3.13 branch.

bedevere-app[bot] avatar May 13 '24 07:05 bedevere-app[bot]