New submission from Brett Hannigan: 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. ---------- components: Library (Lib) files: argparse_test.py messages: 231035 nosy: Brett.Hannigan priority: normal severity: normal status: open title: Subparser help does not respect SUPPRESS argument type: behavior versions: Python 2.7 Added file: http://bugs.python.org/file37177/argparse_test.py _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue22848> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com