gh-139736: Fix argparse indentation overshoot (#139738)
Some checks are pending
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Ubuntu SSL tests with AWS-LC (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run

Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
This commit is contained in:
ed 2025-10-08 15:36:53 +00:00 committed by GitHub
parent 99fd525632
commit 72e370c910
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 7 deletions

View file

@ -280,7 +280,7 @@ class HelpFormatter(object):
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)

View file

@ -7311,11 +7311,11 @@ class TestColorized(TestCase):
{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 @@ class TestColorized(TestCase):
{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
'''))

View file

@ -0,0 +1,2 @@
Fix excessive indentation in the default :mod:`argparse`
:class:`!HelpFormatter`. Patch by Alexander Edland.