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

Skip to content

Commit 7cb20a8

Browse files
committed
Issue #9347: Fix formatting for tuples in argparse type= error messages.
1 parent 43bf045 commit 7cb20a8

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
@@ -1287,13 +1287,13 @@ def add_argument(self, *args, **kwargs):
12871287
# create the action object, and add it to the parser
12881288
action_class = self._pop_action_class(kwargs)
12891289
if not _callable(action_class):
1290-
raise ValueError('unknown action "%s"' % action_class)
1290+
raise ValueError('unknown action "%s"' % (action_class,))
12911291
action = action_class(**kwargs)
12921292

12931293
# raise an error if the action type is not callable
12941294
type_func = self._registry_get('type', action.type, action.type)
12951295
if not _callable(type_func):
1296-
raise ValueError('%r is not callable' % type_func)
1296+
raise ValueError('%r is not callable' % (type_func,))
12971297

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

Lib/test/test_argparse.py

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

40524052
def test_invalid_type(self):
40534053
self.assertValueError('--foo', type='int')
4054+
self.assertValueError('--foo', type=(int, float))
40544055

40554056
def test_invalid_action(self):
40564057
self.assertValueError('-x', action='foo')
40574058
self.assertValueError('foo', action='baz')
4059+
self.assertValueError('--foo', action=('store', 'append'))
40584060
parser = argparse.ArgumentParser()
40594061
try:
40604062
parser.add_argument("--foo", action="store-true")

Misc/NEWS

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

189189
- Issue #9026: Fix order of argparse sub-commands in help messages.
190190

191+
- Issue #9347: Fix formatting for tuples in argparse type= error messages.
192+
191193
Build
192194
-----
193195

0 commit comments

Comments
 (0)