Issue #9347: Fix formatting for tuples in argparse type= error messages.

This commit is contained in:
Steven Bethard 2011-04-04 02:10:40 +02:00
commit 7c8ea37d9b
3 changed files with 6 additions and 2 deletions

View File

@ -1312,13 +1312,13 @@ class _ActionsContainer(object):
# create the action object, and add it to the parser # create the action object, and add it to the parser
action_class = self._pop_action_class(kwargs) action_class = self._pop_action_class(kwargs)
if not _callable(action_class): if not _callable(action_class):
raise ValueError('unknown action "%s"' % action_class) raise ValueError('unknown action "%s"' % (action_class,))
action = action_class(**kwargs) action = action_class(**kwargs)
# raise an error if the action type is not callable # raise an error if the action type is not callable
type_func = self._registry_get('type', action.type, action.type) type_func = self._registry_get('type', action.type, action.type)
if not _callable(type_func): 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 # raise an error if the metavar does not match the type
if hasattr(self, "_get_formatter"): if hasattr(self, "_get_formatter"):

View File

@ -4082,10 +4082,12 @@ class TestInvalidArgumentConstructors(TestCase):
def test_invalid_type(self): def test_invalid_type(self):
self.assertValueError('--foo', type='int') self.assertValueError('--foo', type='int')
self.assertValueError('--foo', type=(int, float))
def test_invalid_action(self): def test_invalid_action(self):
self.assertValueError('-x', action='foo') self.assertValueError('-x', action='foo')
self.assertValueError('foo', action='baz') self.assertValueError('foo', action='baz')
self.assertValueError('--foo', action=('store', 'append'))
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
try: try:
parser.add_argument("--foo", action="store-true") parser.add_argument("--foo", action="store-true")

View File

@ -349,6 +349,8 @@ Library
- Issue #9026: Fix order of argparse sub-commands in help messages. - Issue #9026: Fix order of argparse sub-commands in help messages.
- Issue #9347: Fix formatting for tuples in argparse type= error messages.
Build Build
----- -----