Open
Description
Bug report
Using ArgumentDefaultsHelpFormatter as formatter_class of ArgumentParser doesn't always shows default even if the default for argument is set. It's expected to show default if provided.
Example:
parser = ArgumentParser(formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('foo', default=1)
parser.add_argument('bar', nargs='*', default=1)
parser.add_argument('baz', nargs='*', default=1, help='baz help')
parser.add_argument('-a', default=1)
parser.add_argument('-b', default=1, help='b_help')
parser.print_help()
provides
positional arguments:
foo
bar
baz baz help (default: 1)
options:
-h, --help show this help message and exit
-a A
-b B b_help (default: 1)
Though I see no reason to not show default for -a, foo and bar.
Making help argument mandatory to show default is necessary imho, but what is really strange is that it's enough for an option, but requires nargs for a positional argument.
Your environment
- CPython versions tested on: 3.10.5
- Operating system and architecture: Arch Linux x86_64 5.15.55-1-lts