Skip to content

fix: preserve shared option callback values#3562

Open
suzunn wants to merge 1 commit into
pallets:mainfrom
suzunn:fix-shared-option-callback-value
Open

fix: preserve shared option callback values#3562
suzunn wants to merge 1 commit into
pallets:mainfrom
suzunn:fix-shared-option-callback-value

Conversation

@suzunn

@suzunn suzunn commented Jun 6, 2026

Copy link
Copy Markdown

Problem

Shared options that target the same parameter can process the same parser value more than once. When one option has a callback and another sibling option does not, the callback result can be overwritten by the sibling's raw parser value. In #2786 this allows an internal flag_value sentinel to reach the command callback when only the shortcut flag is provided.

Solution

I tightened the shared-parameter arbitration so a callback-less option with the same command-line source does not replace an existing processed value with a different raw value. This preserves the callback result while keeping the existing explicit-source ordering behavior for normal shared options.

I also added regression coverage for the flag-only case and both mixed ordering cases:

  • --fetch keeps the callback result
  • --custom typed --fetch lets the later flag win
  • --fetch --custom typed lets the later explicit value win

Testing

  • uv run --group tests pytest tests\test_options.py -k "shared_option_callback_value_is_preserved or default_dual_option_callback" -q
  • uv run --group tests pytest tests\test_options.py -q
  • uv run ruff check src\click\core.py tests\test_options.py
  • uv run --group tests pytest -q
  • git diff --check

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant