[docs] [issue9694] argparse required arguments displayed under "optional arguments"

paul j3 report at bugs.python.org
Fri Feb 14 08:32:12 CET 2014

paul j3 added the comment:

Here's another possible solution: add a `help_groups` parameter to ArgumentParser.  It is a list of base argument group names.  `parser.add_argument(...)' places the action in one of those groups.

This is a generalization of the current code which creates two groups titled 'positional arguments' and 'optional arguments', and assigns actions based on 'optional strings' (e.g. '-f','--foo').

'help_groups' could have 1, 2, or 3 items.  

1 - just one argument group

2 - the current postional/optional split, but with user chosen names

3 - a 'positional', 'required', and 'optional' split.  

A 4 way split that distinguishes splits positionals between those that allow 0 values and 1 or more, is possible, but probably not that useful.

The changes are in the ArgumentParser.__init__ and _add_action methods.

'subparsers' do not inherit this parameter.  I have not explored how it plays out with 'parents'. 'test_argparse.py' runs fine.

keywords: +patch
Added file: http://bugs.python.org/file34073/helpgroups.diff

Python tracker <report at bugs.python.org>

More information about the docs mailing list