]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] Update argparse `suggest_on_error` code snippet in docs (GH-144985) (#145151)
authorSavannah Ostrowski <savannah@python.org>
Mon, 23 Feb 2026 17:35:04 +0000 (09:35 -0800)
committerGitHub <noreply@github.com>
Mon, 23 Feb 2026 17:35:04 +0000 (17:35 +0000)
Update argparse `suggest_on_error` code snippet in docs (#144985)

(cherry picked from commit 6194a552f2b010e1dcdd006996f613c956520124)

Doc/library/argparse.rst

index df7a127eb6dfdf0bc264c0b80ac8858074c4af4b..b80f0d2900599eb8266b48a7235b1c2dbb7cdf5c 100644 (file)
@@ -604,13 +604,11 @@ subparser names, the feature can be enabled by setting ``suggest_on_error`` to
 ``True``. Note that this only applies for arguments when the choices specified
 are strings::
 
-   >>> parser = argparse.ArgumentParser(description='Process some integers.',
-                                        suggest_on_error=True)
-   >>> parser.add_argument('--action', choices=['sum', 'max'])
-   >>> parser.add_argument('integers', metavar='N', type=int, nargs='+',
-   ...                     help='an integer for the accumulator')
-   >>> parser.parse_args(['--action', 'sumn', 1, 2, 3])
-   tester.py: error: argument --action: invalid choice: 'sumn', maybe you meant 'sum'? (choose from 'sum', 'max')
+   >>> parser = argparse.ArgumentParser(suggest_on_error=True)
+   >>> parser.add_argument('--action', choices=['debug', 'dryrun'])
+   >>> parser.parse_args(['--action', 'debugg'])
+   usage: tester.py [-h] [--action {debug,dryrun}]
+   tester.py: error: argument --action: invalid choice: 'debugg', maybe you meant 'debug'? (choose from debug, dryrun)
 
 If you're writing code that needs to be compatible with older Python versions
 and want to opportunistically use ``suggest_on_error`` when it's available, you