[New-bugs-announce] [issue44383] argparse.BooleanOptionalAction interacts poorly with ArgumentDefaultsHelpFormatter

Julian Gilbey report at bugs.python.org
Thu Jun 10 14:07:47 EDT 2021


New submission from Julian Gilbey <julian-python at d-and-j.net>:

With code like the following:

~~~~

import argparse

parser = argparse.ArgumentParser(
    description="Test program",
    formatter_class=argparse.ArgumentDefaultsHelpFormatter,
)
parser.add_argument(
    "--foo",
    help="Use the foo component.",
    action=argparse.BooleanOptionalAction,
    default=True,
)

args = parser.parse_args()

~~~~

a call "python prog.py --help" then gives:

~~~~
usage: prog.py [-h] [--foo | --no-foo]

Test program

optional arguments:
  -h, --help       show this help message and exit
  --foo, --no-foo  Use the foo component. (default: True) (default: True)
~~~~

Note the repeated "(default: True)", one produced by the BooleanOptionalAction class and the other by the ArgumentDefaultsHelpFormatter.  It would be good if they didn't both add this helpful information.

My suggestion would be that BooleanOptionalAction should not include this information; it is unique in doing so.

----------
components: Library (Lib)
messages: 395559
nosy: juliangilbey
priority: normal
severity: normal
status: open
title: argparse.BooleanOptionalAction interacts poorly with ArgumentDefaultsHelpFormatter
type: behavior
versions: Python 3.9

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


More information about the New-bugs-announce mailing list