classification
Title: argparse.BooleanOptionalAction interacts poorly with ArgumentDefaultsHelpFormatter
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: duplicate
Dependencies: Superseder:
Assigned To: Nosy List: a.badger, juliangilbey
Priority: normal Keywords:

Created on 2021-06-10 18:07 by juliangilbey, last changed 2021-07-09 05:47 by juliangilbey. This issue is now closed.

Messages (3)
msg395559 - (view) Author: Julian Gilbey (juliangilbey) Date: 2021-06-10 18:07
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.
msg397169 - (view) Author: Toshio Kuratomi (a.badger) * Date: 2021-07-08 20:34
I believe this is a duplicate of https://bugs.python.org/issue38956 and could be closed in favor of that issue.

38956 also has a Pull Request to fix the issue which is awaiting a re-review.
msg397187 - (view) Author: Julian Gilbey (juliangilbey) Date: 2021-07-09 05:46
Yes, this is a duplicate. Marking this report as a duplicate. It's a shame that the other one has a conflict and has been sitting waiting for an update for over a year :-(
I'd be happy to help if it is of use.
History
Date User Action Args
2021-07-09 05:47:33juliangilbeysetstatus: open -> closed
stage: resolved
2021-07-09 05:46:49juliangilbeysetresolution: duplicate
messages: + msg397187
2021-07-08 20:34:58a.badgersetnosy: + a.badger
messages: + msg397169
2021-06-10 18:07:47juliangilbeycreate