Do not offer value completions for boolean flags (fixes #116) - #136
Merged
auvipy merged 2 commits intoAug 4, 2026
Merged
Conversation
A click option declared with is_flag=True (including --foo/--no-foo style flags with secondary opts) does not consume a value. The completer was matching such flags against BoolParamType and offering true/false completions; selecting one inserted the value into the positional-argument slot, causing the command to error. Gate value completions in _get_completion_from_params on the param not being a flag, and add completer regression tests. Fixes click-contrib#116.
There was a problem hiding this comment.
Pull request overview
This PR fixes boolean flag options (is_flag=True, including --foo/--no-foo) incorrectly receiving true/false value completions, which could insert an extra positional argument and cause Click to error.
Changes:
- Prevent value completions from being generated for Click parameters that are flags (
param.is_flag=True). - Add regression tests to ensure flag options do not offer
true/falsecompletions, including secondary option forms. - Document the change in the changelog under “Unreleased”.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
click_repl/_completer.py |
Gates boolean (and other) value completion generation to skip flag parameters. |
tests/test_completion/test_common_tests/test_option_completion.py |
Adds regression tests asserting no value completions are offered for is_flag=True options. |
Changelog.rst |
Adds an Unreleased entry describing the fixed completion behavior for boolean flags. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
auvipy
approved these changes
Aug 4, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@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.
Summary
Fixes #116.
A click option declared with
is_flag=True(astore_true-style flag) does notconsume a value. However,
ClickCompletermatched such flags againstBoolParamTypeand offeredtrue/falsevalue completions once the flag hadbeen typed. Selecting one of those completions inserted the value into the
positional-argument slot, so the command then errored with an unexpected extra
argument. Flags declared with a secondary option (
--foo/--no-foo) were affectedin the same way.
Fix
Value completions are produced in
ClickCompleter._get_completion_from_params.The fix gates that logic on the parameter not being a flag: if
param.is_flagis true (which also covers--foo/--no-foosecondary opts, sinceclick sets
is_flag=Truefor those too), we return no value completions. This islocalized to the completer and leaves genuine boolean value options
(
type=click.BOOL, nois_flag) untouched — they still completetrue/false.Tests
Added two regression tests in
tests/test_completion/test_common_tests/test_option_completion.py:test_flag_option_offers_no_value— a command with aSTRINGargument plus anis_flag=Trueoption; after the flag is typed, notrue/falsecompletionsare offered (matching the minimal reproduction in the issue).
test_boolean_flag_with_secondary_opts_offers_no_value— a--shout/--no-shoutflag offers no value completions for either opt.
Both tests fail on the pristine code and pass with the fix. The full suite
(
pytest) passes (67 passed, 5 skipped) andflake8 click_repl testsis clean.test_boolean_option(a realtype=click.BOOLvalue option) still passes,confirming non-flag boolean options are unaffected.
Disclosure: prepared with AI assistance; reviewed and verified locally.