GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-87106: Fix `inspect.signature.bind` handling of positional-only arguments with `**kwargs` by jacobtylerwalls · Pull Request #103404 · python/cpython

Conversation

@jacobtylerwalls

@jacobtylerwalls jacobtylerwalls commented Apr 10, 2023 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jacobtylerwalls
pythongh-87106: Fix inspect.signature.bind handling of positional-o…
f2baf1a
…nly arguments with `**kwargs`
@bedevere-bot bedevere-bot mentioned this pull request Apr 10, 2023
Incorrect behavior of inspect.signature(f).bind #87106
Closed
@bedevere-bot bedevere-bot added the awaiting review label Apr 10, 2023
@jacobtylerwalls
fixup: double backticks
487e217
sobolevn
sobolevn reviewed Apr 10, 2023
View reviewed changes

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

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!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/test/test_inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@sobolevn
sobolevn requested a review from larryhastings April 10, 2023 06:44
jacobtylerwalls added 2 commits April 14, 2023 22:54
@jacobtylerwalls
Merge branch 'main' into issue-87106
c1e6af2
@jacobtylerwalls
Avoid having helper function start with "test"
b7cbfe4
@sobolevn sobolevn mentioned this pull request Apr 15, 2023
Incorrect inspect.Signature can be created: pos-only with a default followed by pos-or-kw without one #103556
Closed
@jacobtylerwalls
jacobtylerwalls requested a review from sobolevn July 23, 2023 23:59
jacobtylerwalls added 2 commits November 19, 2023 08:27
@jacobtylerwalls
Merge branch 'main' into issue-87106
600e778
@jacobtylerwalls
Merge branch 'main' into issue-87106
eebae66
@jacobtylerwalls

jacobtylerwalls commented May 4, 2024

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sobolevn
Merge branch 'main' into issue-87106
1c7aa83
sobolevn
sobolevn reviewed May 5, 2024
View reviewed changes

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

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.

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

Thanks a lot for your work!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jacobtylerwalls reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread Lib/test/test_inspect/test_inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_inspect/test_inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

jacobtylerwalls and others added 6 commits May 5, 2024 09:37
@jacobtylerwalls @sobolevn
Opt for black style
cc2d7ba
Co-authored-by: Nikita Sobolev <[email protected]>
@jacobtylerwalls
Simplify test case
366bb96
@jacobtylerwalls
Add test cases
2f792eb
@jacobtylerwalls
Use elif
5951ad9
@jacobtylerwalls
Refactor to avoid pop-and-maybe-put-back pattern
2ecde83
@jacobtylerwalls
Remove unnecessary cosmetic changes
db2d925
jacobtylerwalls
jacobtylerwalls commented May 5, 2024
View reviewed changes
Comment thread Lib/inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jacobtylerwalls
Test multiple pos-only args passed by keyword
6916290
@jacobtylerwalls
jacobtylerwalls requested a review from sobolevn May 5, 2024 15:15
@jacobtylerwalls

jacobtylerwalls commented May 5, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

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()?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

sobolevn
sobolevn approved these changes May 9, 2024
View reviewed changes

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

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.

@serhiy-storchaka do you have any additional feedback?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels May 9, 2024
@serhiy-storchaka
serhiy-storchaka self-requested a review May 9, 2024 13:17
serhiy-storchaka
serhiy-storchaka reviewed May 9, 2024
View reviewed changes
Comment thread Lib/test/test_inspect/test_inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/test/test_inspect/test_inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

jacobtylerwalls added 2 commits May 10, 2024 08:27
@jacobtylerwalls
Remove superfluous continue
1ec398b
@jacobtylerwalls
[tests] Use distinct value for c_po kwarg
f1565de
@jacobtylerwalls
jacobtylerwalls requested a review from serhiy-storchaka May 10, 2024 12:38
serhiy-storchaka
serhiy-storchaka reviewed May 10, 2024
View reviewed changes
Comment thread Lib/test/test_inspect/test_inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Lib/inspect.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@jacobtylerwalls
fixup! [tests] Use distinct value for c_po kwarg
52facb0
serhiy-storchaka
serhiy-storchaka approved these changes May 12, 2024
View reviewed changes

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@serhiy-storchaka
serhiy-storchaka merged commit 9c15202 into python:main May 13, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label May 13, 2024
@serhiy-storchaka serhiy-storchaka added needs backport to 3.12 only security fixes needs backport to 3.13 only security fixes labels May 13, 2024
@miss-islington-app

miss-islington-app Bot commented 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.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@miss-islington-app

miss-islington-app Bot commented 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.13.
🐍🍒⛏🤖

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 13, 2024
@jacobtylerwalls @miss-islington
pythongh-87106: Fix inspect.signature.bind() handling of positional-o…
4c23ae3
…nly arguments with **kwargs (pythonGH-103404)

(cherry picked from commit 9c15202)

Co-authored-by: Jacob Walls <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request May 13, 2024
@jacobtylerwalls @miss-islington
pythongh-87106: Fix inspect.signature.bind() handling of positional-o…
256c4be
…nly arguments with **kwargs (pythonGH-103404)

(cherry picked from commit 9c15202)

Co-authored-by: Jacob Walls <[email protected]>
@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.12 only security fixes label May 13, 2024
@bedevere-app

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 only security fixes label May 13, 2024
serhiy-storchaka pushed a commit that referenced this pull request May 13, 2024
@miss-islington @jacobtylerwalls
[3.12] gh-87106: Fix inspect.signature.bind() handling of positional-…
35649df
…only arguments with **kwargs (GH-103404) (GH-118984)

(cherry picked from commit 9c15202)

Co-authored-by: Jacob Walls <[email protected]>
serhiy-storchaka pushed a commit that referenced this pull request May 13, 2024
@miss-islington @jacobtylerwalls
[3.13] gh-87106: Fix inspect.signature.bind() handling of positional-…
a8ea966
…only arguments with **kwargs (GH-103404) (#118985)

(cherry picked from commit 9c15202)

Co-authored-by: Jacob Walls <[email protected]>
@JelleZijlstra JelleZijlstra mentioned this pull request May 28, 2024
backport a9a74da 3.13 #119642
Closed
estyxx pushed a commit to estyxx/cpython that referenced this pull request Jul 17, 2024
@jacobtylerwalls @estyxx
pythongh-87106: Fix inspect.signature.bind() handling of positional-o…
8786b75
…nly arguments with **kwargs (pythonGH-103404)
@hoodmane hoodmane mentioned this pull request Nov 6, 2024
Upgrade to Python 3.12.7 pyodide/pyodide#5149
Merged
6 tasks done
@dfremont dfremont mentioned this pull request Feb 15, 2025
Signature.bind allows certain positional-only parameters as keywords #130164
Closed
@jacobtylerwalls
jacobtylerwalls deleted the issue-87106 branch February 15, 2025 23:42
@jacobtylerwalls jacobtylerwalls mentioned this pull request Feb 17, 2025
gh-130164: Fix inspect.Signature.bind() handling of positional-only args without defaults #130192
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@serhiy-storchaka serhiy-storchaka serhiy-storchaka approved these changes
@sobolevn sobolevn sobolevn approved these changes
@larryhastings larryhastings Awaiting requested review from larryhastings

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Incorrect behavior of inspect.signature(f).bind

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@jacobtylerwalls @serhiy-storchaka @sobolevn @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.