Defaults conditionally omitted from help message when using ArgumentDefaultsHelpFormatter
未关闭
还没有人认领这个 Issue。
stdlib
type-feature
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 36k
- PR 合并指标
- PR 指标待抓取
描述
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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先,使用 ArgumentDefaultsHelpFormatter 重现所提供的 ArgumentParser 示例,并检查 formatter 对位置参数和可选参数的行为。检查链接的 PR gh-112682 以了解现有工作;完成的标准是,在所报告的情况下,帮助输出始终显示所提供的默认值。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- cli
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100