]> granicus.if.org Git - python/commitdiff
Issue #9347: Fix formatting for tuples in argparse type= error messages.
authorSteven Bethard <steven.bethard@gmail.com>
Sun, 3 Apr 2011 23:47:52 +0000 (01:47 +0200)
committerSteven Bethard <steven.bethard@gmail.com>
Sun, 3 Apr 2011 23:47:52 +0000 (01:47 +0200)
Lib/argparse.py
Lib/test/test_argparse.py
Misc/NEWS

index 5b5598fc26c5273f4f9823dff6e7af1cc34e1d64..a9129de470a0d620537f72c3f291a573a1343ae9 100644 (file)
@@ -1277,13 +1277,13 @@ class _ActionsContainer(object):
         # 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"):
index 89a437dd4021de7c17fd0b3eb1799d4fbcb4f15e..5785eec57fb1ad7fca804b9abc20385df3d9cd1b 100644 (file)
@@ -4016,10 +4016,12 @@ class TestInvalidArgumentConstructors(TestCase):
 
     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")
index 9b68a72c0d760ce8077f241261b380cc7055701f..6748638cb8937ce199447af909e4bbf4d6ba41db 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -257,6 +257,8 @@ Library
 
 - Issue #9026: Fix order of argparse sub-commands in help messages.
 
+- Issue #9347: Fix formatting for tuples in argparse type= error messages.
+
 Extension Modules
 -----------------