python / python/cpython

Defaults conditionally omitted from help message when using ArgumentDefaultsHelpFormatter

未关闭
#95,889 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

首先,使用 ArgumentDefaultsHelpFormatter 重现所提供的 ArgumentParser 示例,并检查 formatter 对位置参数和可选参数的行为。检查链接的 PR gh-112682 以了解现有工作;完成的标准是,在所报告的情况下,帮助输出始终显示所提供的默认值。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
cli
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
描述清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。