[issue29626] Issue with spacing in argparse module while using help

Cheryl Sabella report at bugs.python.org
Sat May 27 21:05:58 EDT 2017


Cheryl Sabella added the comment:

I submitted a PR for this based on paul.j3's suggested change:

      def _format_action_invocation(self, action):
           ....
           for option_string in action.option_strings:
               if len(args_string)>0:
                    parts.append('%s %s' % (option_string, args_string))
               else:
                    parts.append('%s' % option_string)
           ....

I created a test that would have duplicated the original issue and, with the change, no longer prints the extra blank.

To Serhiy's point, I'm not sure if an empty metavar makes sense since it's intention is to give the parser a way to refer to the expected arguments within the help messages. 

However, with no metavar at all, the help output is:
  -f FOO, --foo FOO

With metavar = '' (and this change), the output is:
-f, --foo 

With metavar = '' (and without this change), the output is:
-f , --foo

----------
nosy: +csabella

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29626>
_______________________________________


More information about the Python-bugs-list mailing list