← 返回首页
gh-87106: Fix `inspect.signature.bind` handling of positional-only arguments with `**kwargs` by jacobtylerwalls · Pull Request #103404 · python/cpython · GitHub
Skip to content

Navigation Menu

Toggle navigation
Sign in
Appearance settings
Search or jump to...

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Include my email address so I can be contacted

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Resetting focus

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

Merged
serhiy-storchaka merged 17 commits into
python:mainfrom
jacobtylerwalls:issue-87106
May 13, 2024
Merged

gh-87106: Fix inspect.signature.bind handling of positional-only arguments with **kwargs#103404
serhiy-storchaka merged 17 commits into
python:mainfrom
jacobtylerwalls:issue-87106

Conversation

jacobtylerwalls commented Apr 10, 2023
edited
Loading

Copy link
Copy Markdown
Contributor

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

sobolevn 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 Hide comment

Thanks!

Comment thread Lib/test/test_inspect.py Outdated Show resolved Hide resolved
Comment thread Lib/test/test_inspect.py Show resolved Hide resolved
sobolevn requested a review from larryhastings April 10, 2023 06:44

Copy link
Copy Markdown
Contributor Author

👋 @sobolevn would you be interested to take another look?

sobolevn 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 Hide comment

I agree with the fix in general. However, there are still some things to polish and improve :)

Thanks a lot for your work!

Comment thread Lib/test/test_inspect/test_inspect.py Show resolved Hide resolved
Comment thread Lib/test/test_inspect/test_inspect.py Outdated Show resolved Hide resolved
Comment thread Lib/inspect.py Outdated Show resolved Hide resolved
Comment thread Lib/inspect.py Outdated Show resolved Hide resolved
Comment thread Lib/inspect.py Outdated Show resolved Hide resolved
Comment thread Lib/inspect.py Show resolved Hide resolved
jacobtylerwalls requested a review from sobolevn May 5, 2024 15:15

jacobtylerwalls commented May 5, 2024
edited
Loading

Copy link
Copy Markdown
Contributor Author

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

sobolevn 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 Hide comment

@serhiy-storchaka do you have any additional feedback?

Comment thread Lib/test/test_inspect/test_inspect.py Outdated Show resolved Hide resolved
Comment thread Lib/test/test_inspect/test_inspect.py Outdated Show resolved Hide resolved
Comment thread Lib/inspect.py Outdated Show resolved Hide resolved
Comment thread Lib/inspect.py Show resolved Hide resolved
13 hidden items Load more…
Comment thread Lib/test/test_inspect/test_inspect.py Outdated Show resolved Hide resolved
Comment thread Lib/inspect.py Show resolved Hide resolved

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 Hide comment

LGTM.

serhiy-storchaka merged commit 9c15202 into python:main May 13, 2024
serhiy-storchaka added needs backport to 3.12 only security fixes needs backport to 3.13 bugs and security fixes labels May 13, 2024

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.
🐍🍒⛏🤖

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 May 13, 2024
…nly arguments with **kwargs (pythonGH-103404) (cherry picked from commit 9c15202) Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 13, 2024
…nly arguments with **kwargs (pythonGH-103404) (cherry picked from commit 9c15202) Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>

bedevere-app Bot commented May 13, 2024

Copy link
Copy Markdown

GH-118984 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 May 13, 2024

bedevere-app Bot commented May 13, 2024

Copy link
Copy Markdown

GH-118985 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 May 13, 2024
serhiy-storchaka pushed a commit that referenced this pull request May 13, 2024
…only arguments with **kwargs (GH-103404) (GH-118984) (cherry picked from commit 9c15202) Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request May 13, 2024
…only arguments with **kwargs (GH-103404) (#118985) (cherry picked from commit 9c15202) Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
jacobtylerwalls deleted the issue-87106 branch February 15, 2025 23:42
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.

Incorrect behavior of inspect.signature(f).bind

4 participants

Footer

© 2026 GitHub, Inc.