Conversation
When multiple options share a parameter name (a feature-switch group), an option that was not invoked on the command line read its sibling's parsed value out of the parser results and, because unspecified options are processed last, overwrote the value the invoked option's callback had already produced. Track the parameters actually seen by the parser (Context._invoked_params) and skip adopting a command-line value in consume_value when this option was not invoked but a sibling sharing its name was. The un-invoked option now falls back to its own envvar/default instead. Adds a regression test and a CHANGES entry. fixes pallets#2786 Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
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.
When several options share the same parameter name (a "feature-switch"
group, e.g. a plain
--customplus aflag_value--fetchthat maps to thesame function argument), invoking only one of them produced the wrong value.
The parser stores command-line values keyed by the shared
name. Becauseoptions the user did not give are processed last, the un-invoked option read
the sibling's parsed value out of the parser results and overwrote the value
the invoked option's
callbackhad already produced — so--fetchaloneyielded the raw sentinel instead of the callback's result.
This change tracks the parameters the parser actually saw
(
Context._invoked_params) and, inParameter.consume_value, skips adopting acommand-line value when this option was not invoked but a sibling sharing its
namewas. The un-invoked option falls back to its own envvar/default.This also fixes the secondary report: the "callback on both options" workaround
no longer calls the callback twice.
fixes #2786
Checklist (CONTRIBUTING.rst)
(
tests/test_options.py::test_flag_value_group_callback_not_overridden).CHANGES.rstentry under the unreleased 8.5.0 section.change, so no
.. versionchanged::needed.)AI usage disclosure
This change was prepared with the assistance of an AI coding agent; the diagnosis,
patch, and regression test were reviewed and verified locally by the author.