[3.12] GH-87041: Fix incorrect indentation in argparse help (GH-124230) (GH-124374)

In case of usage a long command along with max_help_position more than
the length of the command, the command's help was incorrectly started
on the new line.

(cherry picked from commit 7ee9921734)

Co-authored-by: Savannah Ostrowski <savannahostrowski@gmail.com>
Co-authored-by: Pavel Ditenbir <pavel.ditenbir@gmail.com>
This commit is contained in:
Miss Islington (bot) 2024-09-23 22:16:45 +02:00 committed by GitHub
parent 62dcb8e013
commit 7cc773ba3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 44 additions and 4 deletions

View file

@ -263,13 +263,12 @@ class HelpFormatter(object):
# find all invocations
get_invocation = self._format_action_invocation
invocations = [get_invocation(action)]
invocation_lengths = [len(get_invocation(action)) + self._current_indent]
for subaction in self._iter_indented_subactions(action):
invocations.append(get_invocation(subaction))
invocation_lengths.append(len(get_invocation(subaction)) + self._current_indent)
# update the maximum item length
invocation_length = max(map(len, invocations))
action_length = invocation_length + self._current_indent
action_length = max(invocation_lengths)
self._action_max_length = max(self._action_max_length,
action_length)