Skip to content

Commit 6194a55

Browse files
Update argparse suggest_on_error code snippet in docs (#144985)
1 parent 8db8fc9 commit 6194a55

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

Doc/library/argparse.rst

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -602,18 +602,13 @@ choices (if specified) or subparser names, along with a "maybe you meant"
602602
suggestion if a close match is found. Note that this only applies for arguments
603603
when the choices specified are strings::
604604

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

615-
>>> parser = argparse.ArgumentParser(description='Process some integers.',
616-
suggest_on_error=False)
611+
You can disable suggestions by setting ``suggest_on_error`` to ``False``.
617612

618613
.. versionadded:: 3.14
619614
.. versionchanged:: 3.15

0 commit comments

Comments
 (0)