[Python-checkins] cpython (2.7): Issue #9347: Fix formatting for tuples in argparse type= error messages.

steven.bethard python-checkins at python.org
Mon Apr 4 02:14:42 CEST 2011


http://hg.python.org/cpython/rev/f961e9179998
changeset: 69125:f961e9179998
branch: 2.7
parent: 69080:5e7fc2a42c3c
user: Steven Bethard <steven.bethard at gmail.com>
date: Mon Apr 04 01:47:52 2011 +0200
summary:
 Issue #9347: Fix formatting for tuples in argparse type= error messages.
files:
 Lib/argparse.py | 4 ++--
 Lib/test/test_argparse.py | 2 ++
 Misc/NEWS | 2 ++
 3 files changed, 6 insertions(+), 2 deletions(-)
diff --git a/Lib/argparse.py b/Lib/argparse.py
--- 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
--- 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")
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -257,6 +257,8 @@
 
 - Issue #9026: Fix order of argparse sub-commands in help messages.
 
+- Issue #9347: Fix formatting for tuples in argparse type= error messages.
+
 Extension Modules
 -----------------
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /