https://github.com/python/cpython/commit/68d86eb18a91226975eec5523d2d55d4796b1211
commit: 68d86eb18a91226975eec5523d2d55d4796b1211
branch: main
author: Lazizbek Ergashev <[email protected]>
committer: savannahostrowski <[email protected]>
date: 2026-09-25T16:13:05Z
summary:

gh-157127: Reword the argparse mutually exclusive group error message (#157134)

files:
A Misc/NEWS.d/next/Library/2026-09-08-00-31-56.gh-issue-157127.gduPd0.rst
M Doc/library/argparse.rst
M Lib/argparse.py
M Lib/test/test_argparse.py
M Lib/test/translationdata/argparse/msgids.txt

diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst
index fc5302d875fc1f..c88c10030fb369 100644
--- a/Doc/library/argparse.rst
+++ b/Doc/library/argparse.rst
@@ -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
diff --git a/Lib/argparse.py b/Lib/argparse.py
index 38e1c0d0ed78fd..4cf5dca148c969 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -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
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index 75beb5ede13fef..3abdb3244570a5 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -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)
 
@@ -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',
@@ -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):
diff --git a/Lib/test/translationdata/argparse/msgids.txt 
b/Lib/test/translationdata/argparse/msgids.txt
index ae89ac74726ecf..8a2305b89a5667 100644
--- a/Lib/test/translationdata/argparse/msgids.txt
+++ b/Lib/test/translationdata/argparse/msgids.txt
@@ -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
diff --git 
a/Misc/NEWS.d/next/Library/2026-09-08-00-31-56.gh-issue-157127.gduPd0.rst 
b/Misc/NEWS.d/next/Library/2026-09-08-00-31-56.gh-issue-157127.gduPd0.rst
new file mode 100644
index 00000000000000..614c85fafa264a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-09-08-00-31-56.gh-issue-157127.gduPd0.rst
@@ -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.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to