summaryrefslogtreecommitdiff
path: root/Lib/argparse.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-10-13 10:15:43 -0700
committerGitHub <noreply@github.com>2021-10-13 19:15:43 +0200
commitfd2be6da2ffec2301a58aefa92f17f0c567fbc55 (patch)
treeadcd1ee8f2476a365c087390bc970dc5b0112825 /Lib/argparse.py
parentf8473f6f7603f8cccccc3307d4cb853587be41b3 (diff)
downloadcpython-git-fd2be6da2ffec2301a58aefa92f17f0c567fbc55.tar.gz
bpo-24444: fix an error in argparse help when help for an option is blank (GH-28050) (GH-28931)
(cherry picked from commit 6fafc25aea8689048314b5bf7a9bb986bb1ce238) Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
Diffstat (limited to 'Lib/argparse.py')
-rw-r--r--Lib/argparse.py11
1 files changed, 6 insertions, 5 deletions
diff --git a/Lib/argparse.py b/Lib/argparse.py
index ce4635adcb..f1f6f3227b 100644
--- a/Lib/argparse.py
+++ b/Lib/argparse.py
@@ -526,12 +526,13 @@ class HelpFormatter(object):
parts = [action_header]
# if there was help for the action, add lines of help text
- if action.help:
+ if action.help and action.help.strip():
help_text = self._expand_help(action)
- help_lines = self._split_lines(help_text, help_width)
- parts.append('%*s%s\n' % (indent_first, '', help_lines[0]))
- for line in help_lines[1:]:
- parts.append('%*s%s\n' % (help_position, '', line))
+ if help_text:
+ help_lines = self._split_lines(help_text, help_width)
+ parts.append('%*s%s\n' % (indent_first, '', help_lines[0]))
+ for line in help_lines[1:]:
+ parts.append('%*s%s\n' % (help_position, '', line))
# or add a newline if the description doesn't end with one
elif not action_header.endswith('\n'):