Title: argparse.BooleanOptionalAction interacts poorly with ArgumentDefaultsHelpFormatter
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.9
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: juliangilbey
Priority: normal Keywords:

Created on 2021-06-10 18:07 by juliangilbey, last changed 2021-06-10 18:07 by juliangilbey.

Messages (1)
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",
    help="Use the foo component.",

args = parser.parse_args()


a call "python --help" then gives:

usage: [-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.
Date User Action Args
2021-06-10 18:07:47juliangilbeycreate