Skip to content

Case insensitive shell completions for Choice(..., case_sensitive=False)#1693

Merged
davidism merged 1 commit into
pallets:masterfrom
felixnorden:1692-case-sensitive-shell-completions
Nov 1, 2020
Merged

Case insensitive shell completions for Choice(..., case_sensitive=False)#1693
davidism merged 1 commit into
pallets:masterfrom
felixnorden:1692-case-sensitive-shell-completions

Conversation

@felixnorden

Copy link
Copy Markdown
Contributor

This PR adds the logic and a test for checking case insensitive completions for Choice instances which have the argument case_sensitive=False.

What changed was having the Choice class' shell_complete-method take self.case_sensitive into account when matching on the provided instance choices by using temporary string transforms on the incomplete argument and self.choices into all lower case when self.case_sensitive=False.

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed. (NOTE: No test results changed with this contribution, there was 1 failing test though)

@bgschiller bgschiller left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the quick PR! It might be worth adding a test for the opposite behavior: that case sensitive choice don't autocomplete when the case doesn't match.

Comment thread tests/test_shell_completion.py Outdated
@felixnorden

Copy link
Copy Markdown
Contributor Author

Sorry for the delay, I have added a test case for this as well and the tests are passing as expected :)

@davidism davidism force-pushed the 1692-case-sensitive-shell-completions branch from 4fb7d61 to d5857c8 Compare November 1, 2020 02:56
@davidism

davidism commented Nov 1, 2020

Copy link
Copy Markdown
Member

Refactored to avoid using an inner function. Refactored test to use paremtrize and test choices both cases.

Co-authored-by: David Lord <davidism@gmail.com>
@davidism davidism force-pushed the 1692-case-sensitive-shell-completions branch from d5857c8 to b964c1e Compare November 1, 2020 02:58
@davidism davidism added the f:completion feature: shell completion label Nov 1, 2020
@davidism davidism added this to the 8.0.0 milestone Nov 1, 2020
@davidism davidism merged commit 5eb46cb into pallets:master Nov 1, 2020
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Nov 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f:completion feature: shell completion

Projects

None yet

Development

Successfully merging this pull request may close these issues.

shell completion is case sensitive, even with click.Choice(case_sensitive=False)

3 participants