Skip to content

Commit a27f627

Browse files
test(optparse): add regression test for tuple callback_kwargs raising OptionError
A tuple callback_kwargs should raise OptionError with the repr of the tuple, not TypeError from string formatting unpacking the tuple.
1 parent ec94729 commit a27f627

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

Lib/test/test_optparse.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,16 @@ def test_callback_kwargs_no_dict(self):
301301
'callback': self.dummy,
302302
'callback_kwargs': 'foo'})
303303

304+
def test_callback_kwargs_tuple_not_dict(self):
305+
# A tuple callback_kwargs should raise OptionError, not TypeError
306+
# from string formatting unpacking the tuple.
307+
self.assertOptionError(
308+
"option -b: callback_kwargs, if supplied, "
309+
"must be a dict: not (1, 2)",
310+
["-b"], {'action': 'callback',
311+
'callback': self.dummy,
312+
'callback_kwargs': (1, 2)})
313+
304314
def test_no_callback_for_action(self):
305315
self.assertOptionError(
306316
"option -b: callback supplied ('foo') for non-callback option",

0 commit comments

Comments
 (0)