Message355342
So the error occurs in HelpFormatter._format_action when 'help_lines' is an empty list:
....
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]))
for line in help_lines[1:]:
parts.append('%*s%s\n' % (help_position, '', line))
It occurs with both optionals and positionals. It does not occur with argparse.RawTextHelpFormatter.
The default _split_lines:
def _split_lines(self, text, width):
text = self._whitespace_matcher.sub(' ', text).strip()
return _textwrap.wrap(text, width)
Because of the 'strip' it treats a help with space as empty
In [27]: f._split_lines('',40)
Out[27]: []
In [28]: f._split_lines('test',40)
Out[28]: ['test']
In [29]: f._split_lines(' ',40)
Out[29]: []
None or '' don't trigger this because they are weeded out by the 'if action.help:' line.
Maybe the change proposed here, to skip the problem line if 'help_lines' is empty is the right one. Assuming a list is non-empty can be dangerous. But it would be wise to test the patch with the alternative formatters like the RawText.
It may also be worth thinking about correcting the issue in _split_lines(), which is shorter. The only difference in RawTextHelpFormatter is in this method. |
|
Date |
User |
Action |
Args |
2019-10-24 17:15:15 | paul.j3 | set | recipients:
+ paul.j3, rhettinger, Lucas Cimon |
2019-10-24 17:15:15 | paul.j3 | set | messageid: <1571937315.09.0.306292344035.issue38584@roundup.psfhosted.org> |
2019-10-24 17:15:15 | paul.j3 | link | issue38584 messages |
2019-10-24 17:15:14 | paul.j3 | create | |
|