Skip to content
2 changes: 1 addition & 1 deletion Lib/optparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,7 +706,7 @@ def _check_callback(self):
not isinstance(self.callback_kwargs, dict)):
raise OptionError(
"callback_kwargs, if supplied, must be a dict: not %r"
% self.callback_kwargs, self)
% (self.callback_kwargs,), self)
else:
if self.callback is not None:
raise OptionError(
Expand Down
8 changes: 8 additions & 0 deletions Lib/test/test_optparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,14 @@ def test_callback_kwargs_no_dict(self):
'callback': self.dummy,
'callback_kwargs': 'foo'})

def test_callback_kwargs_tuple_not_dict(self):
self.assertOptionError(
"option -b: callback_kwargs, if supplied, "
"must be a dict: not (1, 2)",
["-b"], {'action': 'callback',
'callback': self.dummy,
'callback_kwargs': (1, 2)})

def test_no_callback_for_action(self):
self.assertOptionError(
"option -b: callback supplied ('foo') for non-callback option",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
:mod:`optparse`: raise :exc:`~optparse.OptionError` instead of :exc:`TypeError`
when ``callback_kwargs`` is not a dictionary.
Loading