Click 8.5.0: omitted boolean flags incorrectly trigger conflicting_options validation

未關閉
#112 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

@nicu1989 已經在處理了。

開始於 2026年11月13日。

  • #113 來自 @nicu1989 —— 未關閉

評估

難度
3/5
預估耗時
1-2 天
新手友好度
66/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
python
領域
cli

研究方向

The bug is in validate_option_dependencies() and PluggableCommandLineOption in the commoncode cliutils module, which decide whether an option counts as used. Run the reproduction script from the issue with click 8.5.0 and again with 8.4.2 to compare. Find how the check tells a supplied flag from a default, since click 8.5.0 seems to report omitted flags differently. Done when the script prints OK on click 8.5.0 and a regression test covers omitted boolean flags.

由索引模型根據 Issue 內容生成。

描述

With commoncode 33.0.0 and click 8.5.0, validate_option_dependencies() incorrectly reports a conflict between mutually exclusive boolean flags when neither flag is supplied:

Error: The option --strip-root cannot be used together with the --full-root option(s) and --full-root is used. You can set only one of these options at a time.

This breaks scancode 32.4.1 with conflict between --strip-root and --full-root. The problem reproduces using commoncode alone as well.
Tested with Python 3.12. CommonCode 32.4.2 is also affected. The same checks pass with Click 8.4.2.

How to standalone reproduce the error:

  1. Create test.py:
import click
from commoncode import cliutils

@click.command()
@click.option(
    "--strip-root", is_flag=True,
    cls=cliutils.PluggableCommandLineOption,
    conflicting_options=["full_root"],
)
@click.option(
    "--full-root", is_flag=True,
    cls=cliutils.PluggableCommandLineOption,
    conflicting_options=["strip_root"],
)
@click.pass_context
def cli(ctx, strip_root, full_root):
    cliutils.validate_option_dependencies(ctx)
    click.echo("OK")

if __name__ == "__main__":
    cli()
  1. Use packages: python -m pip install commoncode==33.0.0 click==8.5.0
  2. Run: python test.py -> expected output: OK, actual: Error: The option --strip-root cannot be used together with the --full-root option(s) and --full-root is used. You can set only one of these options at a time.

With click 8.4.2 the out put is OK.

主要語言
Python
星號
4
分支
25
PR 合併指標
30 天內沒有已合併 PR

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

aboutcode-org/commoncode 的其他 Issue

查看 aboutcode-org/commoncode 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。