Skip to content

Commit 8b34bcc

Browse files
[3.14] Update argparse suggest_on_error code snippet in docs (GH-144985) (#145151)
Update argparse `suggest_on_error` code snippet in docs (#144985) (cherry picked from commit 6194a55)
1 parent 5f1c450 commit 8b34bcc

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

Doc/library/argparse.rst

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -604,13 +604,11 @@ subparser names, the feature can be enabled by setting ``suggest_on_error`` to
604604
``True``. Note that this only applies for arguments when the choices specified
605605
are strings::
606606

607-
>>> parser = argparse.ArgumentParser(description='Process some integers.',
608-
suggest_on_error=True)
609-
>>> parser.add_argument('--action', choices=['sum', 'max'])
610-
>>> parser.add_argument('integers', metavar='N', type=int, nargs='+',
611-
... help='an integer for the accumulator')
612-
>>> parser.parse_args(['--action', 'sumn', 1, 2, 3])
613-
tester.py: error: argument --action: invalid choice: 'sumn', maybe you meant 'sum'? (choose from 'sum', 'max')
607+
>>> parser = argparse.ArgumentParser(suggest_on_error=True)
608+
>>> parser.add_argument('--action', choices=['debug', 'dryrun'])
609+
>>> parser.parse_args(['--action', 'debugg'])
610+
usage: tester.py [-h] [--action {debug,dryrun}]
611+
tester.py: error: argument --action: invalid choice: 'debugg', maybe you meant 'debug'? (choose from debug, dryrun)
614612

615613
If you're writing code that needs to be compatible with older Python versions
616614
and want to opportunistically use ``suggest_on_error`` when it's available, you

0 commit comments

Comments
 (0)