From 07327c2ba5f1a525283370e0170687eba7581cb5 Mon Sep 17 00:00:00 2001 From: Justin Kunimune Date: Tue, 3 Mar 2026 10:26:49 -0500 Subject: [PATCH 1/3] fix incorrect statement in argparse docs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The documentation for the name or flags argument of `argparse.ArgumentParser.add_argument()` said > By default, argparse automatically handles the internal naming and display names of arguments … The dest parametre defaults to the argument name with underscores `_` replacing hyphens `-` . However, this is not true for positional arguments, which retain their hyphens. The documentation for the dest parameter correctly describes this behavior, but a user who only reads the name or flags documentation will be misled. Thus, I added a qualification to the sentence to make clear that the hyphen relpacement only happens for optional argiments. --- 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 ca4f439c345f32..b10391a2dd2a56 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -739,9 +739,9 @@ By default, :mod:`!argparse` automatically handles the internal naming and display names of arguments, simplifying the process without requiring additional configuration. As such, you do not need to specify the dest_ and metavar_ parameters. -The dest_ parameter defaults to the argument name with underscores ``_`` -replacing hyphens ``-`` . The metavar_ parameter defaults to the -upper-cased name. For example:: +The dest_ parameter defaults to the argument name, with underscores ``_`` +replacing hyphens ``-`` if the argument is optional . The metavar_ +parameter defaults to the upper-cased name. For example:: >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('--foo-bar') From 2e7ff210b52cedaa1e6eeddf65ef8c18bd33a38d Mon Sep 17 00:00:00 2001 From: Justin Kunimune Date: Tue, 3 Mar 2026 16:11:11 -0500 Subject: [PATCH 2/3] adjust phrasing in argparse docs Co-authored-by: Savannah Ostrowski --- Doc/library/argparse.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/argparse.rst b/Doc/library/argparse.rst index b10391a2dd2a56..f7c5b9ca168c5c 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -739,8 +739,8 @@ By default, :mod:`!argparse` automatically handles the internal naming and display names of arguments, simplifying the process without requiring additional configuration. As such, you do not need to specify the dest_ and metavar_ parameters. -The dest_ parameter defaults to the argument name, with underscores ``_`` -replacing hyphens ``-`` if the argument is optional . The metavar_ +For optional arguments, the dest_ parameter defaults to the argument name, with underscores ``_`` +replacing hyphens ``-``. The metavar_ parameter defaults to the upper-cased name. For example:: >>> parser = argparse.ArgumentParser(prog='PROG') From 400df48a2649e3db000714e1e0470e0ed601194f Mon Sep 17 00:00:00 2001 From: Justin Kunimune Date: Tue, 3 Mar 2026 16:26:27 -0500 Subject: [PATCH 3/3] adjust linebreak in argparse docs --- 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 f7c5b9ca168c5c..8f31e815e0eb4b 100644 --- a/Doc/library/argparse.rst +++ b/Doc/library/argparse.rst @@ -739,9 +739,9 @@ By default, :mod:`!argparse` automatically handles the internal naming and display names of arguments, simplifying the process without requiring additional configuration. As such, you do not need to specify the dest_ and metavar_ parameters. -For optional arguments, the dest_ parameter defaults to the argument name, with underscores ``_`` -replacing hyphens ``-``. The metavar_ -parameter defaults to the upper-cased name. For example:: +For optional arguments, the dest_ parameter defaults to the argument name, with +underscores ``_`` replacing hyphens ``-``. The metavar_ parameter defaults to +the upper-cased name. For example:: >>> parser = argparse.ArgumentParser(prog='PROG') >>> parser.add_argument('--foo-bar')