Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Doc/library/argparse.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2099,7 +2099,7 @@ Mutual exclusion
>>> group.add_argument('--bar', action='store_false')
>>> parser.parse_args([])
usage: PROG [-h] (--foo | --bar)
PROG: error: one of the arguments --foo --bar is required
PROG: error: one of the following arguments is required: --foo, --bar

Note that currently mutually exclusive argument groups do not support the
*title* and *description* arguments of
Expand Down
4 changes: 2 additions & 2 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2499,8 +2499,8 @@ def consume_positionals(start_index):
names = [_get_action_name(action)
for action in group._group_actions
if action.help is not SUPPRESS]
msg = _('one of the arguments %s is required')
raise ArgumentError(None, msg % ' '.join(names))
msg = _('one of the following arguments is required: %s')
raise ArgumentError(None, msg % ', '.join(names))

# return the updated namespace and the extra arguments
return namespace, extras
Expand Down
6 changes: 3 additions & 3 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -6866,7 +6866,7 @@ def test_required_exclusive(self):
args = parser.parse_intermixed_args('1 --foo 2'.split())
self.assertEqual(NS(badger=['1', '2'], foo=True, spam=None), args)
self.assertRaisesRegex(argparse.ArgumentError,
'one of the arguments --foo --spam is required',
'one of the following arguments is required: --foo, --spam',
parser.parse_intermixed_args, '1 2'.split())
self.assertEqual(group.required, True)

Expand All @@ -6882,7 +6882,7 @@ def test_required_exclusive_with_positional(self):
args = parser.parse_intermixed_args(['a', 'b'])
self.assertEqual(NS(foo=False, spam=None, badger=['a', 'b']), args)
self.assertRaisesRegex(argparse.ArgumentError,
'one of the arguments --foo --spam badger is required',
'one of the following arguments is required: --foo, --spam, badger',
parser.parse_intermixed_args, [])
self.assertRaisesRegex(argparse.ArgumentError,
'argument badger: not allowed with argument --foo',
Expand Down Expand Up @@ -7258,7 +7258,7 @@ def test_required_mutually_exclusive_args(self):
group.add_argument('--bar')
group.add_argument('--baz')
self.assertRaisesRegex(argparse.ArgumentError,
'one of the arguments --bar --baz is required',
'one of the following arguments is required: --bar, --baz',
self.parser.parse_args, [])

def test_conflicting_mutually_exclusive_args_optional_with_metavar(self):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/translationdata/argparse/msgids.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ invalid %(type)s value: %(value)r
invalid choice: %(value)r (choose from %(choices)s)
invalid choice: %(value)r, maybe you meant %(closest)r? (choose from %(choices)s)
not allowed with argument %s
one of the arguments %s is required
one of the following arguments is required: %s
option '%(option)s' is deprecated
options
positional arguments
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Reword the :mod:`argparse` error message reported for a missing required
mutually exclusive group to ``one of the following arguments is required:
--foo, --bar``, so that the argument names are separated by commas.
Loading