Message231035
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. |
|
Date |
User |
Action |
Args |
2014-11-11 17:51:37 | Brett.Hannigan | set | recipients:
+ Brett.Hannigan |
2014-11-11 17:51:37 | Brett.Hannigan | set | messageid: <1415728297.74.0.809984326992.issue22848@psf.upfronthosting.co.za> |
2014-11-11 17:51:37 | Brett.Hannigan | link | issue22848 messages |
2014-11-11 17:51:37 | Brett.Hannigan | create | |
|