Skip to content
Myr

handle case_sensitive=False when completing choices

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Felix Nordén · committed by David Lord · parent acc91bc · Browse files · 3 files+20 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: David Lord <davidism@gmail.com>

Diff stats

3 files+20 added−1 removed

  • tests:+10 added−0 removed
  • other:+10 added−1 removed

3 files+20 added−1 removed

modified:src/click/types.py+8 added-1 removed
272 unmodified lines
273 """274 from click.shell_completion import CompletionItem275276 str_choices = map(str, self.choices)277 return [CompletionItem(c) for c in str_choices if c.startswith(incomplete)]277278 if self.case_sensitive:279 matched = (c for c in str_choices if c.startswith(incomplete))280 else:281 incomplete = incomplete.lower()282 matched = (c for c in str_choices if c.lower().startswith(incomplete))283284 return [CompletionItem(c) for c in matched]285286287class DateTime(ParamType):288 """The DateTime type converts date strings into `datetime` objects.289290 The format strings which are checked are configurable, but default to some
634 unmodified lines
modified:tests/test_shell_completion.py+10 added
302 unmodified lines
303 obj={"choices": ["a", "b"]},304 env={"COMP_WORDS": "", "COMP_CWORD": "0", "_CLI_COMPLETE": "bash_complete"},305 )306 assert result.output == "plain,a\nplain,b\n"307308309@pytest.mark.parametrize(("value", "expect"), [(False, ["Au", "al"]), (True, ["al"])])310def test_choice_case_sensitive(value, expect):311 cli = Command(312 "cli",313 params=[Option(["-a"], type=Choice(["Au", "al", "Bc"], case_sensitive=value))],314 )315 completions = _get_words(cli, ["-a"], "a")316 assert completions == expect
modified:CHANGES.rst+2 added
149 unmodified lines
150- Automatically generated short help messages will stop at the first151 ending of a phrase or double linebreak. :issue:`1082`152- Skip progress bar render steps for efficiency with very fast153 iterators by setting ``update_min_steps``. :issue:`676`154- Respect ``case_sensitive=False`` when doing shell completion for155 ``Choice`` :issue:`1692`156157158Version 7.1.2159-------------
635 unmodified lines