FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-130164: Fix inspect.Signature.bind() handling of positional-only args without defaults by jacobtylerwalls · Pull Request #130192 · python/cpython · GitHub

/ cpython Public

gh-130164: Fix inspect.Signature.bind() handling of positional-only args without defaults - #130192

Merged
serhiy-storchaka merged 2 commits into
python:mainfrom
jacobtylerwalls:fix-130164
Feb 18, 2025
Merged

gh-130164: Fix inspect.Signature.bind() handling of positional-only args without defaults#130192
serhiy-storchaka merged 2 commits into
python:mainfrom
jacobtylerwalls:fix-130164

Conversation

jacobtylerwalls commented Feb 16, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

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, making assertRaises(TypeError, ... succeed regardless of the behavior of bind().

Closes #130164

(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'"):

jacobtylerwalls Feb 16, 2025
edited
Loading

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Some of these cases could be moved to the existing method test_signature_bind_posonly_kwargs() if desired?

jacobtylerwalls changed the title gh-130164: Fix inspect.signature.bind() handling of positional-only args without defaults gh-130164: Fix inspect.Signature.bind() handling of positional-only args without defaults Feb 16, 2025

dfremont left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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).

Copy link
Copy Markdown
Member

CC @picnixz

Copy link
Copy Markdown
Contributor Author

Thanks for the review (and the original report!)

(the exception message is slightly different than a direct call to the function, but I at least don't care about that).

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.)

serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM. 👍

serhiy-storchaka added the needs backport to 3.13 bugs and security fixes label Feb 18, 2025
serhiy-storchaka merged commit dab456d into python:main Feb 18, 2025

Copy link
Copy Markdown

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 18, 2025
…only args without defaults (pythonGH-130192)

Follow-up to 9c15202.
(cherry picked from commit dab456d)

Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>

bedevere-app Bot commented Feb 18, 2025

Copy link
Copy Markdown

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

bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Feb 18, 2025
jacobtylerwalls deleted the fix-130164 branch February 18, 2025 16:27
serhiy-storchaka pushed a commit that referenced this pull request Apr 8, 2025
…-only args without defaults (GH-130192) (GH-130271)

Follow-up to 9c15202.
(cherry picked from commit dab456d)

Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
serhiy-storchaka added the needs backport to 3.12 only security fixes label Apr 8, 2025

Copy link
Copy Markdown

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

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 8, 2025
…only args without defaults (pythonGH-130192)

Follow-up to 9c15202.
(cherry picked from commit dab456d)

Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>

bedevere-app Bot commented Apr 8, 2025

Copy link
Copy Markdown

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

bedevere-app Bot removed the needs backport to 3.12 only security fixes label Apr 8, 2025
serhiy-storchaka pushed a commit that referenced this pull request Apr 8, 2025
…-only args without defaults (GH-130192) (GH-132259)

Follow-up to 9c15202.
(cherry picked from commit dab456d)

Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Signature.bind allows certain positional-only parameters as keywords

4 participants


Back | FazBrowse Home | New Git URL