This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author paul.j3
Recipients Lucas Cimon, paul.j3, rhettinger
Date 2019-10-24.17:15:14
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1571937315.09.0.306292344035.issue38584@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2019-10-24 17:15:15paul.j3setrecipients: + paul.j3, rhettinger, Lucas Cimon
2019-10-24 17:15:15paul.j3setmessageid: <1571937315.09.0.306292344035.issue38584@roundup.psfhosted.org>
2019-10-24 17:15:15paul.j3linkissue38584 messages
2019-10-24 17:15:14paul.j3create