summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Bethard <steven.bethard@gmail.com>2011-04-03 23:53:02 (GMT)
committerSteven Bethard <steven.bethard@gmail.com>2011-04-03 23:53:02 (GMT)
commit7cb20a8605d79faae64cccf8bbe8418b492f0e30 (patch)
tree5beb0a6acd7f161467c5c905f77c4117e801148c
parent43bf045be09f50c17627bfa3dd2ce386ddf37304 (diff)
downloadcpython-7cb20a8605d79faae64cccf8bbe8418b492f0e30.zip
cpython-7cb20a8605d79faae64cccf8bbe8418b492f0e30.tar.gz
cpython-7cb20a8605d79faae64cccf8bbe8418b492f0e30.tar.bz2
Issue #9347: Fix formatting for tuples in argparse type= error messages.
-rw-r--r--Lib/argparse.py4
-rw-r--r--Lib/test/test_argparse.py2
-rw-r--r--Misc/NEWS2
3 files changed, 6 insertions, 2 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 0ef9f4e..63561f7 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -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"):
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index e187653..5ecfdc7 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -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")
diff --git a/Misc/NEWS b/Misc/NEWS
index 7d817fe..7f67246 100644
--- 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
-----