https://github.com/python/cpython/commit/72e370c910bd941806a36b01f2f57f4c53a78eed
commit: 72e370c910bd941806a36b01f2f57f4c53a78eed
branch: main
author: ed <[email protected]>
committer: savannahostrowski <[email protected]>
date: 2025-10-08T15:36:53Z
summary:

gh-139736: Fix argparse indentation overshoot (#139738)

Co-authored-by: Savannah Ostrowski <[email protected]>

files:
A Misc/NEWS.d/next/Library/2025-10-08-00-06-30.gh-issue-139736.baPeBd.rst
M Lib/argparse.py
M Lib/test/test_argparse.py

diff --git a/Lib/argparse.py b/Lib/argparse.py
index 863e951528b6d0..d71e551401cb02 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -280,7 +280,7 @@ def add_argument(self, action):
         if action.help is not SUPPRESS:
 
             # find all invocations
-            get_invocation = self._format_action_invocation
+            get_invocation = lambda x: 
self._decolor(self._format_action_invocation(x))
             invocation_lengths = [len(get_invocation(action)) + 
self._current_indent]
             for subaction in self._iter_indented_subactions(action):
                 invocation_lengths.append(len(get_invocation(subaction)) + 
self._current_indent)
diff --git a/Lib/test/test_argparse.py b/Lib/test/test_argparse.py
index 90bfcd0ae3e29b..27e38040a98d10 100644
--- a/Lib/test/test_argparse.py
+++ b/Lib/test/test_argparse.py
@@ -7311,11 +7311,11 @@ def custom_formatter(prog):
             {heading}usage: {reset}{prog}PROG{reset} [{short}-h{reset}] 
[{short}+f {label}FOO{reset}] {pos}spam{reset}
 
             {heading}positional arguments:{reset}
-                 {pos_b}spam{reset}               spam help
+                 {pos_b}spam{reset}           spam help
 
             {heading}options:{reset}
-                 {short_b}-h{reset}, {long_b}--help{reset}         show this 
help message and exit
-                 {short_b}+f{reset}, {long_b}++foo{reset} {label_b}FOO{reset}  
    foo help
+                 {short_b}-h{reset}, {long_b}--help{reset}     show this help 
message and exit
+                 {short_b}+f{reset}, {long_b}++foo{reset} {label_b}FOO{reset}  
foo help
         '''))
 
     def test_custom_formatter_class(self):
@@ -7348,11 +7348,11 @@ def __init__(self, prog):
             {heading}usage: {reset}{prog}PROG{reset} [{short}-h{reset}] 
[{short}+f {label}FOO{reset}] {pos}spam{reset}
 
             {heading}positional arguments:{reset}
-                 {pos_b}spam{reset}               spam help
+                 {pos_b}spam{reset}           spam help
 
             {heading}options:{reset}
-                 {short_b}-h{reset}, {long_b}--help{reset}         show this 
help message and exit
-                 {short_b}+f{reset}, {long_b}++foo{reset} {label_b}FOO{reset}  
    foo help
+                 {short_b}-h{reset}, {long_b}--help{reset}     show this help 
message and exit
+                 {short_b}+f{reset}, {long_b}++foo{reset} {label_b}FOO{reset}  
foo help
         '''))
 
 
diff --git 
a/Misc/NEWS.d/next/Library/2025-10-08-00-06-30.gh-issue-139736.baPeBd.rst 
b/Misc/NEWS.d/next/Library/2025-10-08-00-06-30.gh-issue-139736.baPeBd.rst
new file mode 100644
index 00000000000000..820679632d1e26
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-10-08-00-06-30.gh-issue-139736.baPeBd.rst
@@ -0,0 +1,2 @@
+Fix excessive indentation in the default :mod:`argparse`
+:class:`!HelpFormatter`. Patch by Alexander Edland.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to