mirror of
https://github.com/python/cpython.git
synced 2026-05-06 04:37:33 -04:00
[3.13] GH-130750: Restore quoting of choices in argparse error messag… (#149386)
[3.13] GH-130750: Restore quoting of choices in argparse error messages to match documentation and improve clarity (GH-144983)
(cherry picked from commit 53a7f76501)
This commit is contained in:
committed by
GitHub
parent
9f9a273267
commit
a02beabe2d
+1
-1
@@ -2601,7 +2601,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
||||
choices = iter(choices)
|
||||
if value not in choices:
|
||||
args = {'value': str(value),
|
||||
'choices': ', '.join(map(str, action.choices))}
|
||||
'choices': ', '.join(repr(str(choice)) for choice in action.choices)}
|
||||
msg = _('invalid choice: %(value)r (choose from %(choices)s)')
|
||||
raise ArgumentError(action, msg % args)
|
||||
|
||||
|
||||
@@ -1047,7 +1047,7 @@ class TestStrEnumChoices(TestCase):
|
||||
parser.add_argument('--color', choices=self.Color)
|
||||
self.assertRaisesRegex(
|
||||
argparse.ArgumentError,
|
||||
r"invalid choice: 'yellow' \(choose from red, green, blue\)",
|
||||
r"invalid choice: 'yellow' \(choose from 'red', 'green', 'blue'\)",
|
||||
parser.parse_args,
|
||||
['--color', 'yellow'],
|
||||
)
|
||||
@@ -2517,7 +2517,7 @@ class TestAddSubparsers(TestCase):
|
||||
parser.parse_args(('baz',))
|
||||
self.assertRegex(
|
||||
excinfo.exception.stderr,
|
||||
r"error: argument {foo,bar}: invalid choice: 'baz' \(choose from foo, bar\)\n$"
|
||||
r"error: argument {foo,bar}: invalid choice: 'baz' \(choose from 'foo', 'bar'\)\n$"
|
||||
)
|
||||
|
||||
def test_optional_subparsers(self):
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
Restore quoting of choices in :mod:`argparse` error messages for improved clarity and consistency with documentation.
|
||||
|
||||
Reference in New Issue
Block a user