-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-130164: Fix inspect.Signature.bind() handling of positional-only args without defaults #130192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…only arguments without defaults Follow-up to 9c15202.
@@ -5349,7 +5353,7 @@ def test(a_po, b_po, c_po=3, /, foo=42, *, bar=50, **kwargs): | |||
self.assertEqual(self.call(test, 1, 2, c_po=4), | |||
(1, 2, 3, 42, 50, {'c_po': 4})) | |||
|
|||
with self.assertRaisesRegex(TypeError, "missing 2 required positional arguments"): | |||
with self.assertRaisesRegex(TypeError, "missing a required positional-only argument: 'a_po'"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of these cases could be moved to the existing method test_signature_bind_posonly_kwargs()
if desired?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the very quick fix, @jacobtylerwalls! The new logic looks correct to me and does fix the bug I reported (the exception message is slightly different than a direct call to the function, but I at least don't care about that).
CC @picnixz |
Thanks for the review (and the original report!)
Right, this was something I was trying to keep to in the original PR (#103404), but during review discussion there I became convinced it was of only marginal benefit. (This time around it seemed too complicated to be worth it, on first look anyway.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 👍
Thanks @jacobtylerwalls for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
…only args without defaults (pythonGH-130192) Follow-up to 9c15202. (cherry picked from commit dab456d) Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
GH-130271 is a backport of this pull request to the 3.13 branch. |
Thanks @jacobtylerwalls for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
…only args without defaults (pythonGH-130192) Follow-up to 9c15202. (cherry picked from commit dab456d) Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
GH-132259 is a backport of this pull request to the 3.12 branch. |
Before
inspect.Signature.bind()
failed to raise TypeError for positional-only arguments passed by keyword (due to a regression handling the case where a default is defined).After
This is fixed.
Regression in 9c15202.
Interestingly, we did have a test case for this, but it unexpectedly passed because after calling
bind()
, the test helper also calls the underlying function, makingassertRaises(TypeError, ...
succeed regardless of the behavior ofbind()
.Closes #130164