optparse Option._check_callback raises TypeError instead of OptionError for tuple callback_kwargs
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 35.9k
- PR merge metrics
- PR metrics pending
Description
Bug report
Bug description:
Issue
When callback_kwargs is a tuple, Option._check_callback raises TypeError instead of OptionError. The error message is formatted with %r % self.callback_kwargs. When callback_kwargs is a tuple, Python's % operator unpacks it as multiple format arguments, causing TypeError: not all arguments converted during string formatting.
Reproducer
from optparse import Option
Option('--foo', action='callback', callback=lambda *a: None, callback_kwargs=(1, 2))
# TypeError: not all arguments converted during string formatting
# Expected: OptionError
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
- gh-145822
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at optparse.Option._check_callback and reproduce the tuple callback_kwargs case from the issue. Confirm that the invalid callback_kwargs path reports OptionError rather than a formatting TypeError; linked PR gh-145822 indicates work is already underway.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 25/100