gh-99749: Suggest closest choice in argparser, if wrong choice is picked by abdulrafey38 · Pull Request #99831 · python/cpython · GitHub
Skip to content
Closed
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
24 changes: 21 additions & 3 deletions Lib/argparse.py
5 changes: 3 additions & 2 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2193,9 +2193,10 @@ def test_wrong_argument_subparsers_no_destination_error(self):
subparsers.add_parser('bar')
with self.assertRaises(ArgumentParserError) as excinfo:
parser.parse_args(('baz',))
self.assertRegex(
self.assertIn(
"error: argument {foo,bar}: invalid choice: 'baz', maybe you meant 'bar'?"
" (choose from 'foo', 'bar')",
excinfo.exception.stderr,
r"error: argument {foo,bar}: invalid choice: 'baz' \(choose from 'foo', 'bar'\)\n$"
)

def test_optional_subparsers(self):
Expand Down