Issue #9347: Fix formatting for tuples in argparse type= error messages.
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 5b5598f..a9129de 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -1277,13 +1277,13 @@
# create the action object, and add it to the parser
action_class = self._pop_action_class(kwargs)
if not _callable(action_class):
- raise ValueError('unknown action "%s"' % action_class)
+ raise ValueError('unknown action "%s"' % (action_class,))
action = action_class(**kwargs)
# raise an error if the action type is not callable
type_func = self._registry_get('type', action.type, action.type)
if not _callable(type_func):
- raise ValueError('%r is not callable' % type_func)
+ raise ValueError('%r is not callable' % (type_func,))
# raise an error if the metavar does not match the type
if hasattr(self, "_get_formatter"):
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index 89a437d..5785eec 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -4016,10 +4016,12 @@
def test_invalid_type(self):
self.assertValueError('--foo', type='int')
+ self.assertValueError('--foo', type=(int, float))
def test_invalid_action(self):
self.assertValueError('-x', action='foo')
self.assertValueError('foo', action='baz')
+ self.assertValueError('--foo', action=('store', 'append'))
parser = argparse.ArgumentParser()
try:
parser.add_argument("--foo", action="store-true")