Skip to content

optparse Option._check_callback raises TypeError instead of OptionError for tuple callback_kwargs #145821

@stefanzetzsche

Description

@stefanzetzsche

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions