[New-bugs-announce] [issue43259] argparse: allow add_mutually_exclusive_group on add_argument_group

Christoph Anton Mitterer report at bugs.python.org
Thu Feb 18 21:28:41 EST 2021

New submission from Christoph Anton Mitterer <calestyo at scientia.org>:


AFAIU, the sole purpose of ArgumentParser.add_argument_group() is for the grouping within the help output.

It would be nice, if one could create a mutually exclusive group (with ArgumentParser.add_mutually_exclusive_group) from/within such a "normal" group, so that the mutually exclusive arguments are listed within the group, but are still, mutually exclusive.

Right now when doing something like:
    parser = argparse.ArgumentParser()
    parser_group = parser.add_argument_group("INPUT OPTIONS")
    parser_group_mutually_exclusive = parser_group.add_mutually_exclusive_group(required=False)
    parser_group.add_argument("-0", help="null delimited pathnames")

it works, but the mutually exclusive options are note printed within the "INPUT OPTIONS", but rather at the normal "optional arguments:" section of the help.

The above example also kinda shows what this could be used for:
- one might have e.g. a group for input options, and amongst that the mutually exclusive "--from-*" which specify the source of the input.


components: Library (Lib)
messages: 387278
nosy: calestyo
priority: normal
severity: normal
status: open
title: argparse: allow add_mutually_exclusive_group on add_argument_group
type: enhancement

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list