[issue25882] argparse help error: arguments created by add_mutually_exclusive_group() are shown outside their parent group created by add_argument_group()

paul j3 report at bugs.python.org
Thu Dec 17 13:17:24 EST 2015


paul j3 added the comment:

Argument groups are not designed to be nested.

If you print_help the parent parser, you'll see that the sub_args are missing entirely, not just displaced.  They appear in the usage, but not the help lines.  sub_group has no record that it was added to global_group (it doesn't have the ._container attribute).  

All containers, both parsers and groups, have a ._action_groups list (inherited from their common super), but I don't think any of the group code uses that list.  And the part of the help_formatter than handles groups is not recursive.  It handles just one level of groups.

I suspect the sub_group actions appear in the 'optional arguments' group for similar reasons as with the mutually_exclusive_group, but the details probably differ.

There have been a number of questions on SO about using argument_groups to add actions to a mutually_exclusive_group.  They either want a convenient way of adding a group of actions, or they want some sort of 'any'  logic applied to the subgroup.  We've had to say - no you can't nest groups like that.  I have explored in another bug/issue the idea of nesting groups and applying all sorts of logic (not just xor), but that's a big issue.

----------

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


More information about the Python-bugs-list mailing list