[New-bugs-announce] [issue45690] Argparse exclusive group inside required exclusive group displays incorrectly

andrew cooke report at bugs.python.org
Tue Nov 2 09:39:20 EDT 2021


New submission from andrew cooke <andrew at acooke.org>:

The code below, when invoked with -h, prints:

(.env) [andrew at localhost py]$ python -m tests_sa.argparse_bug -h
usage: argparse_bug.py [-h] (-a A | [-b B | -c C)]

options:
  -h, --help  show this help message and exit
  -a A
  -b B
  -c C

where the final two characters in the usage line are swapped.  It should be

usage: argparse_bug.py [-h] (-a A | [-b B | -c C])

or maybe even

usage: argparse_bug.py [-h] (-a A | (-b B | -c C))



from argparse import ArgumentParser

def main():
    parser = ArgumentParser()
    outer = parser.add_mutually_exclusive_group(required=True)
    outer.add_argument('-a')
    inner = outer.add_mutually_exclusive_group()
    inner.add_argument('-b')
    inner.add_argument('-c')
    parser.parse_args()


if __name__ == '__main__':
    main()

----------
components: Library (Lib)
messages: 405509
nosy: acooke
priority: normal
severity: normal
status: open
title: Argparse exclusive group inside required exclusive group displays incorrectly
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45690>
_______________________________________


More information about the New-bugs-announce mailing list