Skip to content

Commit 14c923c

Browse files
miss-islington9001savannahostrowski
authored
[3.14] gh-139736: Fix argparse indentation overshoot (GH-139738) (#139793)
gh-139736: Fix argparse indentation overshoot (GH-139738) (cherry picked from commit 72e370c) Co-authored-by: ed <[email protected]> Co-authored-by: Savannah Ostrowski <[email protected]>
1 parent 4e3fc92 commit 14c923c

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Lib/argparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ def add_argument(self, action):
281281
if action.help is not SUPPRESS:
282282

283283
# find all invocations
284-
get_invocation = self._format_action_invocation
284+
get_invocation = lambda x: self._decolor(self._format_action_invocation(x))
285285
invocation_lengths = [len(get_invocation(action)) + self._current_indent]
286286
for subaction in self._iter_indented_subactions(action):
287287
invocation_lengths.append(len(get_invocation(subaction)) + self._current_indent)

Lib/test/test_argparse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7311,11 +7311,11 @@ def custom_formatter(prog):
73117311
{heading}usage: {reset}{prog}PROG{reset} [{short}-h{reset}] [{short}+f {label}FOO{reset}] {pos}spam{reset}
73127312
73137313
{heading}positional arguments:{reset}
7314-
{pos_b}spam{reset} spam help
7314+
{pos_b}spam{reset} spam help
73157315
73167316
{heading}options:{reset}
7317-
{short_b}-h{reset}, {long_b}--help{reset} show this help message and exit
7318-
{short_b}+f{reset}, {long_b}++foo{reset} {label_b}FOO{reset} foo help
7317+
{short_b}-h{reset}, {long_b}--help{reset} show this help message and exit
7318+
{short_b}+f{reset}, {long_b}++foo{reset} {label_b}FOO{reset} foo help
73197319
'''))
73207320

73217321
def test_custom_formatter_class(self):
@@ -7348,11 +7348,11 @@ def __init__(self, prog):
73487348
{heading}usage: {reset}{prog}PROG{reset} [{short}-h{reset}] [{short}+f {label}FOO{reset}] {pos}spam{reset}
73497349
73507350
{heading}positional arguments:{reset}
7351-
{pos_b}spam{reset} spam help
7351+
{pos_b}spam{reset} spam help
73527352
73537353
{heading}options:{reset}
7354-
{short_b}-h{reset}, {long_b}--help{reset} show this help message and exit
7355-
{short_b}+f{reset}, {long_b}++foo{reset} {label_b}FOO{reset} foo help
7354+
{short_b}-h{reset}, {long_b}--help{reset} show this help message and exit
7355+
{short_b}+f{reset}, {long_b}++foo{reset} {label_b}FOO{reset} foo help
73567356
'''))
73577357

73587358

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix excessive indentation in the default :mod:`argparse`
2+
:class:`!HelpFormatter`. Patch by Alexander Edland.

0 commit comments

Comments
 (0)