This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: argparse mutually_exclusive_group under add_argument_group fails if part of parent_processor
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: duplicate
Dependencies: Superseder: argparse help error: arguments created by add_mutually_exclusive_group() are shown outside their parent group created by add_argument_group()
View: 25882
Assigned To: Nosy List: Paul Traina (discontent), martin.panter
Priority: normal Keywords:

Created on 2017-09-06 03:42 by Paul Traina (discontent), last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg301437 - (view) Author: Paul Traina (discontent) (Paul Traina (discontent)) Date: 2017-09-06 03:42
Hopefully I'm not being obtuse, but I seem to be getting incorrect/unexpected help output when using mutually_exclusive_group under an add_argument_group if this layering is happening in a parent parser.

Here's an example of the triggering usage:

import argparse

global_options = argparse.ArgumentParser(add_help=False)
global_options.add_argument('--summary', action='store_true', help='summarize information')
global_options.add_argument('--verbose', action='store_true', help='tell us more')

output_format = global_options.add_argument_group("Output format", "ways to foo")
styles = output_format.add_mutually_exclusive_group()
styles.add_argument('--plain', dest='style')
styles.add_argument('--green', dest='style')
styles.add_argument('--blue', dest='style')

parser = argparse.ArgumentParser()
commands = parser.add_subparsers()
hit = commands.add_parser('hit', parents=[global_options])
miss = commands.add_parser('miss', parents=[global_options])

print(parser.parse_args(['hit', '-h']))

which produces:

usage: bar.py hit [-h] [--summary] [--verbose]
                  [--plain STYLE | --green STYLE | --blue STYLE]

optional arguments:
  -h, --help     show this help message and exit
  --summary      summarize information
  --verbose      tell us more
  --plain STYLE
  --green STYLE
  --blue STYLE

Output format:
  ways to foo


"--plain" "--green" and "--blue" *should* be under "Output format"
msg301460 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2017-09-06 11:26
Seems the same as two other open bugs: Issue 25882 and Issue 16807.
History
Date User Action Args
2022-04-11 14:58:51adminsetgithub: 75541
2017-09-06 11:26:42martin.pantersetstatus: open -> closed

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

nosy: + martin.panter
messages: + msg301460
resolution: duplicate
stage: resolved
2017-09-06 03:42:16Paul Traina (discontent)create