fix: avoid overwriting shared option callback results#3485
Closed
sjh9714 wants to merge 1 commit into
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2786
Summary
When two options share the same parameter name, such as
--customand--fetch, invoking only--fetchcould 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--fetchwithcustom=$_fetch.uv run pytest tests/test_options.py tests/test_basic.pyuv run pytestuv run ruff check src/click/core.py tests/test_options.pyuv run ruff format --check src/click/core.py tests/test_options.pyuv run tox rpy3.14tandstress-py3.14tenvironments ontests/test_utils.py::test_echo_via_pager. The same fullpy3.14tenvironment also fails on a cleanorigin/maincheckout in my local setup, while the isolateduv run tox r -e py3.14t -- tests/test_utils.py::test_echo_via_pagercommand passes on cleanorigin/main.