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 Brett.Hannigan
Recipients Brett.Hannigan
Date 2014-11-11.17:51:37
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1415728297.74.0.809984326992.issue22848@psf.upfronthosting.co.za>
In-reply-to
Content
When adding an argument to a subparser and passing help=argparse.SUPPRESS, I would expect this argument to not show up when running help.  Instead, I find that the argument is listed and the help given is ==SUPPRESS==.  For example (also in attached python script):
import argparse

parser = argparse.ArgumentParser('test')
subparsers = parser.add_subparsers()
parser_foo = subparsers.add_parser('foo', help='This is help for foo')
parser_bar = subparsers.add_parser('bar', help=argparse.SUPPRESS)

parser.parse_args(['-h'])

usage: test [-h] {foo,bar} ...

positional arguments:
  {foo,bar}
    foo       This is help for foo
    bar       ==SUPPRESS==

optional arguments:
  -h, --help  show this help message and exit

I believe I have found the proper fix in argparse.py
In the class _SubParsersAction look at the method add_parser().
There is the following block of code:

if 'help' in kwargs:
            help = kwargs.pop('help')
            choice_action = self._ChoicesPseudoAction(name, help)
            self._choices_actions.append(choice_action)

This should instead check to see if help is SUPPRESS or not like so:

if 'help' in kwargs:
            help = kwargs.pop('help')
            if help != SUPPRESS:
                choice_action = self._ChoicesPseudoAction(name, help)
                self._choices_actions.append(choice_action)

If I make this change locally, then the above code does in fact suppress printing the bar option.
History
Date User Action Args
2014-11-11 17:51:37Brett.Hannigansetrecipients: + Brett.Hannigan
2014-11-11 17:51:37Brett.Hannigansetmessageid: <1415728297.74.0.809984326992.issue22848@psf.upfronthosting.co.za>
2014-11-11 17:51:37Brett.Hanniganlinkissue22848 messages
2014-11-11 17:51:37Brett.Hannigancreate