]> 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:53:02 +0000 (01:53 +0200)
committerSteven Bethard <steven.bethard@gmail.com>
Sun, 3 Apr 2011 23:53:02 +0000 (01:53 +0200)
Lib/argparse.py
Lib/test/test_argparse.py
Misc/NEWS

index 0ef9f4ee88b92c17ac9390654e8787298ef1faeb..63561f7cb129c80f3a61cadfece4e66bb38f0c66 100644 (file)
@@ -1287,13 +1287,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 e1876534c3273a2b64386e3607477528d728ddde..5ecfdc72ea83554e6ee8ce544542e022ffc79304 100644 (file)
@@ -4051,10 +4051,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 7d817fee8adf1804eafc9f786fa4b890d79eea00..7f67246511983958403355ba5b524478fc6dd82d 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -188,6 +188,8 @@ Library
 
 - Issue #9026: Fix order of argparse sub-commands in help messages.
 
+- Issue #9347: Fix formatting for tuples in argparse type= error messages.
+
 Build
 -----