From eb42ddb7f66a705b30587e03c4ea6110c6e6d49a Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 18 Feb 2026 20:59:05 -0800 Subject: [PATCH 1/2] Update example to be clear, valid code. --- Doc/library/argparse.rst | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 60411b0a0c9748..cc89c43b2ac2d0 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -605,18 +605,12 @@ choices (if specified) or subparser names, along with a "maybe you meant" suggestion if a close match is found. 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') - -You can disable suggestions by setting ``suggest_on_error`` to ``False``:: + >>> parser = argparse.ArgumentParser(suggest_on_error=True) + >>> parser.add_argument('--action', choices=['debug', 'dryrun']) + >>> parser.parse_args(['--action', 'debugg']) + error: argument --action: invalid choice: 'debugg', maybe you meant 'debug'? (choose from 'debug', 'dryrun') - >>> parser = argparse.ArgumentParser(description='Process some integers.', - suggest_on_error=False) +You can disable suggestions by setting ``suggest_on_error`` to ``False``. .. versionadded:: 3.14 .. versionchanged:: 3.15 From 71b9a1e558d45392043ef2534dbe742856d0f2a6 Mon Sep 17 00:00:00 2001 From: Savannah Ostrowski Date: Wed, 18 Feb 2026 21:05:46 -0800 Subject: [PATCH 2/2] Update return --- Doc/library/argparse.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index cc89c43b2ac2d0..c0cd2de0aa1fa9 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -608,7 +608,8 @@ when the choices specified are strings:: >>> parser = argparse.ArgumentParser(suggest_on_error=True) >>> parser.add_argument('--action', choices=['debug', 'dryrun']) >>> parser.parse_args(['--action', 'debugg']) - error: argument --action: invalid choice: 'debugg', maybe you meant 'debug'? (choose from 'debug', 'dryrun') + usage: tester.py [-h] [--action {debug,dryrun}] + tester.py: error: argument --action: invalid choice: 'debugg', maybe you meant 'debug'? (choose from debug, dryrun) You can disable suggestions by setting ``suggest_on_error`` to ``False``.