Defaults conditionally omitted from help message when using ArgumentDefaultsHelpFormatter
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 77.2k
- Forks
- 36k
- PR merge metrics
- PR metrics pending
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
Linked PRs
- gh-112682
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied ArgumentParser example with ArgumentDefaultsHelpFormatter and inspect the formatter behavior for positional and optional arguments. Check the linked PR gh-112682 for existing work; done means the help output consistently shows provided defaults in the reported cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100