Skip to content

fix: avoid overwriting shared option callback results#3485

Closed
sjh9714 wants to merge 1 commit into
pallets:mainfrom
sjh9714:fix-shared-dest-flag-callback
Closed

fix: avoid overwriting shared option callback results#3485
sjh9714 wants to merge 1 commit into
pallets:mainfrom
sjh9714:fix-shared-dest-flag-callback

Conversation

@sjh9714
Copy link
Copy Markdown

@sjh9714 sjh9714 commented May 20, 2026

Fixes #2786

Summary

When two options share the same parameter name, such as --custom and --fetch, invoking only --fetch could run its callback and then have that callback result overwritten by the uninvoked sibling option. In the reported case this exposed the internal sentinel value as $_fetch.

This updates parameter processing so that, once one option with a shared parameter name is invoked, uninvoked siblings with that same name are not processed later. Shared-name options with no invocation still follow the existing default handling, and multiple explicitly invoked options keep the existing invocation-order behavior.

I also added focused regression coverage for --fetch, --custom, both invocation orders, and the no-argument default case, plus a changelog entry.

Testing

  • uv run pytest tests/test_options.py -k shared_dest_flag_callback_value_not_overwritten
    • Before the code change, the new regression failed for --fetch with custom=$_fetch.
    • After the code change, it passes.
  • uv run pytest tests/test_options.py tests/test_basic.py
  • uv run pytest
  • uv run ruff check src/click/core.py tests/test_options.py
  • uv run ruff format --check src/click/core.py tests/test_options.py
  • uv run tox r
    • Local gap: this fails only in the py3.14t and stress-py3.14t environments on tests/test_utils.py::test_echo_via_pager. The same full py3.14t environment also fails on a clean origin/main checkout in my local setup, while the isolated uv run tox r -e py3.14t -- tests/test_utils.py::test_echo_via_pager command passes on clean origin/main.

@davidism davidism closed this May 20, 2026
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.

Multi-value options override the value returned from callback when not all specified

2 participants