Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions Lib/argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,12 +526,13 @@ def _format_action(self, action):
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'):
Expand Down
36 changes: 36 additions & 0 deletions Lib/test/test_argparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,42 @@ def test_help_non_breaking_spaces(self):
wrap\N{NO-BREAK SPACE}at non-breaking spaces
'''))

def test_help_blank(self):
# Issue 24444
parser = ErrorRaisingArgumentParser(
prog='PROG', description='main description')
parser.add_argument(
'foo',
help=' ')
self.assertEqual(parser.format_help(), textwrap.dedent('''\
usage: PROG [-h] foo

main description

positional arguments:
foo

options:
-h, --help show this help message and exit
'''))

parser = ErrorRaisingArgumentParser(
prog='PROG', description='main description')
parser.add_argument(
'foo', choices=[],
help='%(choices)s')
self.assertEqual(parser.format_help(), textwrap.dedent('''\
usage: PROG [-h] {}

main description

positional arguments:
{}

options:
-h, --help show this help message and exit
'''))

def test_help_alternate_prefix_chars(self):
parser = self._get_parser(prefix_chars='+:/')
self.assertEqual(parser.format_usage(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fixed an error raised in :mod:`argparse` help display when help for an
option is set to 1+ blank spaces or when *choices* arg is an empty container.