python / python/cpython

argparse exclusive argument group error unintelligible

未关闭
#157,127 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

stdlib type-bug
主要语言
Python
星标
77.2k
派生
35.9k
PR 合并指标
PR 指标待抓取

描述

Bug report

Bug description:
    import argparse
    import os.path
    parser = argparse.ArgumentParser()
    parser.add_argument(
        "--debug",
        action="store_true",
        help="print out debugging information",
    )
    # Added optional branch argument
    parser.add_argument(
        "-b",
        "--branch",
        default="main",
        help="branch name to store commits in (default: main)",
    )
    parser.add_argument(
        "--non-interactive",
        action="store_true",
        help="disable interactive prompts for missing author information, pass --yes to lfs import",
    )
    parser.add_argument(
        "--template",
        default=os.path.join(
            os.path.dirname(__file__), "template"
        ),
        help="add files from this directory to every revision",
    )
    parser.add_argument(
        "--object-format",
        default="sha256",
        help="git object format to use (default: sha256)",
    )
    parser.add_argument(
        "--changelog",
        nargs="?",
        const=pkg_base,
        help="use changelog for commit messages, "
        f"package name is guessed ({pkg_base}) or can be specified",
    )
    repo_group = parser.add_mutually_exclusive_group(required=True)
    repo_group.add_argument(
        "--stdout",
        action="store_true",
        help="output git fast-import data to stdout",
    )
    repo_group.add_argument(
        "repository",
        nargs="?",
        help="import package into this git repository if --stdout is not given",
    )
    args = parser.parse_args()

$ python3 osc_fast_export.py 
usage: osc_fast_export.py [-h] [--debug] [-b BRANCH] [--non-interactive] [--template TEMPLATE]
                          [--object-format OBJECT_FORMAT] [--changelog [CHANGELOG]] (--stdout |
                          repository)
osc_fast_export.py: error: one of the arguments --stdout repository is required

The sentence

one of the arguments --stdout repository is required

is unintelligible. I wrote the code so I know why the output is like this but this is supposed to be read by a user who never looked at the code. The grammar of that sentence is broken.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Linked PRs
  • gh-157134

贡献指南

打开贡献指南

从这里开始

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

调研方向

从报告中展示的 argparse mutually exclusive-group 入口点开始,在既不使用 --stdout 也不使用 repository 的情况下复现该命令。跟踪由此产生的必需参数诊断及其现有覆盖;完成的标准是,面向用户的消息语法正确、清楚地说明这一要求,并为此情况提供回归测试。

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

评估

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

把新 issue 发到你的邮箱

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