Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7c8ea37

Browse files
committed
Issue #9347: Fix formatting for tuples in argparse type= error messages.
2 parents fc2e376 + 7cb20a8 commit 7c8ea37

3 files changed

Lines changed: 6 additions & 2 deletions

File tree

Lib/argparse.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,13 +1312,13 @@ def add_argument(self, *args, **kwargs):
13121312
# create the action object, and add it to the parser
13131313
action_class = self._pop_action_class(kwargs)
13141314
if not _callable(action_class):
1315-
raise ValueError('unknown action "%s"' % action_class)
1315+
raise ValueError('unknown action "%s"' % (action_class,))
13161316
action = action_class(**kwargs)
13171317

13181318
# raise an error if the action type is not callable
13191319
type_func = self._registry_get('type', action.type, action.type)
13201320
if not _callable(type_func):
1321-
raise ValueError('%r is not callable' % type_func)
1321+
raise ValueError('%r is not callable' % (type_func,))
13221322

13231323
# raise an error if the metavar does not match the type
13241324
if hasattr(self, "_get_formatter"):

Lib/test/test_argparse.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4082,10 +4082,12 @@ def test_invalid_option_strings(self):
40824082

40834083
def test_invalid_type(self):
40844084
self.assertValueError('--foo', type='int')
4085+
self.assertValueError('--foo', type=(int, float))
40854086

40864087
def test_invalid_action(self):
40874088
self.assertValueError('-x', action='foo')
40884089
self.assertValueError('foo', action='baz')
4090+
self.assertValueError('--foo', action=('store', 'append'))
40894091
parser = argparse.ArgumentParser()
40904092
try:
40914093
parser.add_argument("--foo", action="store-true")

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,8 @@ Library
349349

350350
- Issue #9026: Fix order of argparse sub-commands in help messages.
351351

352+
- Issue #9347: Fix formatting for tuples in argparse type= error messages.
353+
352354
Build
353355
-----
354356

0 commit comments

Comments
 (0)