bpo-38584: fix a bug in argparse with whitespace-only help messages
This commit is contained in:
parent
d2810054c7
commit
617616e1c5
|
@ -529,7 +529,8 @@ class HelpFormatter(object):
|
|||
if action.help:
|
||||
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]))
|
||||
if help_lines:
|
||||
parts.append('%*s%s\n' % (indent_first, '', help_lines[0]))
|
||||
for line in help_lines[1:]:
|
||||
parts.append('%*s%s\n' % (help_position, '', line))
|
||||
|
||||
|
|
|
@ -4688,6 +4688,15 @@ class TestOptionalsHelpVersionActions(TestCase):
|
|||
self.assertPrintHelpExit(parser, format % '--help')
|
||||
self.assertRaises(AttributeError, getattr, parser, 'format_version')
|
||||
|
||||
def test_whitespace_help(self):
|
||||
for formatter_class in (argparse.ArgumentDefaultsHelpFormatter, argparse.HelpFormatter,
|
||||
argparse.MetavarTypeHelpFormatter,
|
||||
argparse.RawDescriptionHelpFormatter, argparse.RawTextHelpFormatter):
|
||||
parser = argparse.ArgumentParser(formatter_class=formatter_class)
|
||||
parser.add_argument('--foo', action='store_true', help=' ')
|
||||
parser.add_argument('bar', type=float, help=' ')
|
||||
parser.format_help() # does not raise any error
|
||||
|
||||
|
||||
# ======================
|
||||
# str() and repr() tests
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fix a minor bug in argparse with whitespace-only argument help messages
|
Loading…
Reference in New Issue