Skip to content

Commit 29ccff3

Browse files
committed
gh-157127: Separate names with commas in argparse mutually exclusive group error
1 parent dcc4e52 commit 29ccff3

4 files changed

Lines changed: 7 additions & 5 deletions

File tree

‎Doc/library/argparse.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,7 @@ Mutual exclusion
20992099
>>> group.add_argument('--bar', action='store_false')
21002100
>>> parser.parse_args([])
21012101
usage: PROG [-h] (--foo | --bar)
2102-
PROG: error: one of the arguments --foo --bar is required
2102+
PROG: error: one of the arguments --foo, --bar is required
21032103

21042104
Note that currently mutually exclusive argument groups do not support the
21052105
*title* and *description* arguments of

‎Lib/argparse.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2500,7 +2500,7 @@ def consume_positionals(start_index):
25002500
for action in group._group_actions
25012501
if action.help is not SUPPRESS]
25022502
msg = _('one of the arguments %s is required')
2503-
raise ArgumentError(None, msg % ' '.join(names))
2503+
raise ArgumentError(None, msg % ', '.join(names))
25042504

25052505
# return the updated namespace and the extra arguments
25062506
return namespace, extras

‎Lib/test/test_argparse.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6866,7 +6866,7 @@ def test_required_exclusive(self):
68666866
args = parser.parse_intermixed_args('1 --foo 2'.split())
68676867
self.assertEqual(NS(badger=['1', '2'], foo=True, spam=None), args)
68686868
self.assertRaisesRegex(argparse.ArgumentError,
6869-
'one of the arguments --foo --spam is required',
6869+
'one of the arguments --foo, --spam is required',
68706870
parser.parse_intermixed_args, '1 2'.split())
68716871
self.assertEqual(group.required, True)
68726872

@@ -6882,7 +6882,7 @@ def test_required_exclusive_with_positional(self):
68826882
args = parser.parse_intermixed_args(['a', 'b'])
68836883
self.assertEqual(NS(foo=False, spam=None, badger=['a', 'b']), args)
68846884
self.assertRaisesRegex(argparse.ArgumentError,
6885-
'one of the arguments --foo --spam badger is required',
6885+
'one of the arguments --foo, --spam, badger is required',
68866886
parser.parse_intermixed_args, [])
68876887
self.assertRaisesRegex(argparse.ArgumentError,
68886888
'argument badger: not allowed with argument --foo',
@@ -7258,7 +7258,7 @@ def test_required_mutually_exclusive_args(self):
72587258
group.add_argument('--bar')
72597259
group.add_argument('--baz')
72607260
self.assertRaisesRegex(argparse.ArgumentError,
7261-
'one of the arguments --bar --baz is required',
7261+
'one of the arguments --bar, --baz is required',
72627262
self.parser.parse_args, [])
72637263

72647264
def test_conflicting_mutually_exclusive_args_optional_with_metavar(self):
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Separate the argument names with commas in the :mod:`argparse` error message
2+
reported for a missing required mutually exclusive group.

0 commit comments

Comments
 (0)