From afcec4c7e7b15bb346b2e0b2b7f90660dc07088e Mon Sep 17 00:00:00 2001 From: Timothy Poon <62692924+ptim0626@users.noreply.github.com> Date: Fri, 7 Aug 2026 18:48:07 +0100 Subject: [PATCH] gh-155352: Fix inconsistent error messages between parse_args and documentation (GH-155353) (cherry picked from commit 4ccb6000881842956152d007013d9507f3099227) Co-authored-by: Timothy Poon <62692924+ptim0626@users.noreply.github.com> --- Doc/library/argparse.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index 7508aea2aed0840..9709d7e4435770b 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -1541,12 +1541,12 @@ it exits and prints the error along with a usage message:: >>> # invalid option >>> parser.parse_args(['--bar']) usage: PROG [-h] [--foo FOO] [bar] - PROG: error: no such option: --bar + PROG: error: unrecognized arguments: --bar >>> # wrong number of arguments >>> parser.parse_args(['spam', 'badger']) usage: PROG [-h] [--foo FOO] [bar] - PROG: error: extra arguments found: badger + PROG: error: unrecognized arguments: badger Arguments containing ``-`` @@ -1583,7 +1583,7 @@ there are no options in the parser that look like negative numbers:: >>> # negative number options present, so -2 is an option >>> parser.parse_args(['-2']) usage: PROG [-h] [-1 ONE] [foo] - PROG: error: no such option: -2 + PROG: error: unrecognized arguments: -2 >>> # negative number options present, so both -1s are options >>> parser.parse_args(['-1', '-1'])