gh-145821: properly raise OptionError in Option._check_callback when callback_kwargs is invalid#145822
Open
stefanzetzsche wants to merge 6 commits intopython:mainfrom
Open
Conversation
…wargs %r % tuple unpacks the tuple as multiple format args, raising TypeError instead of OptionError. Wrap in a 1-tuple: % (value,).
…parse_callback_kwargs_typeerror
picnixz
requested changes
Mar 11, 2026
Member
picnixz
left a comment
There was a problem hiding this comment.
Please add a regression test.
Misc/NEWS.d/next/Library/2026-03-11-14-14-27.gh-issue-145821.xWSIjR.rst
Outdated
Show resolved
Hide resolved
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
OptionError when callback_kwargs is invalid
OptionError when callback_kwargs is invalidOptionError when callback_kwargs is invalid
OptionError when callback_kwargs is invalidOptionError in Option._check_callback when callback_kwargs is invalid
…WSIjR.rst Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
… OptionError A tuple callback_kwargs should raise OptionError with the repr of the tuple, not TypeError from string formatting unpacking the tuple.
…ub.com/stefanzetzsche/cpython into fix/optparse_callback_kwargs_typeerror
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
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.
Issue
Option._check_callbackformats its error message with%r % self.callback_kwargs. Whencallback_kwargsis a tuple, Python's%operator unpacks it as multiple arguments, causingTypeErrorinstead of the expectedOptionError.Reproducer
Fix
In
Lib/optparse.py, wrap the value in a tuple for the format call:Tests
Added
test_callback_kwargs_tuple_not_dicttoTestOptionChecksinLib/test/test_optparse.py.