click icon indicating copy to clipboard operation
click copied to clipboard

[rejected AI] Case-insensitive Choice completion misses Unicode case-folding matches

Open januththedev opened this issue 2 months ago • 2 comments

Description

Choice uses casefold() for case-insensitive conversion, but shell_complete() lowercases the incomplete value and compares it with lower(). This makes completion fail for Unicode case-folding expansions.

For example, Choice(["ẞ"], case_sensitive=False) accepts "ß" during conversion because both values case-fold to "ss", but completion for the incomplete value "ß" returns no suggestion because "ss".lower().startswith("ß") is false.

Steps to reproduce

from click import Choice

choice = Choice(["ẞ"], case_sensitive=False)
assert choice.convert("ß", None, None) == "ẞ"

# A completion callback using this Choice receives incomplete="ß".
# It currently produces no completion item, even though the normalized choice is "ss".

The relevant implementation is Choice.shell_complete() in src/click/types.py; it uses lower() while normalize_choice() uses casefold().

Expected behavior

Case-insensitive shell completion should use the same Unicode-aware normalization as conversion and return the normalized "ss" suggestion for incomplete "ß".

Actual behavior

No completion item is returned.

Environment

  • Latest main at the time of filing
  • Python 3.12+
  • Click shell completion

I searched existing issues and pull requests for Unicode casefolding and Choice completion and did not find a matching report. A regression test covering ẞ/ß would prevent this from recurring.

januththedev avatar Sep 24 '26 15:09 januththedev

I prepared and pushed a focused fix on januththedev:fix/unicode-casefold-completion:

  • commit: fb499f6
  • branch: https://github.com/januththedev/click/tree/fix/unicode-casefold-completion
  • changes: use Unicode casefold() consistently in shell completion, add a ẞ/ß regression test, add a changelog entry and versionchanged note
  • verification: 59 passed in tests/test_shell_completion.py; compileall and git diff --check passed

GitHub rejected PR creation for this account with does not have the correct permissions to execute CreatePullRequest, apparently due Click's first-time-contributor controls. Could a maintainer approve this contribution or open the equivalent PR from the branch when possible?

januththedev avatar Sep 24 '26 15:09 januththedev

Now why would you create this PR via the API and not via the GH web interface? Because you are using some AI agent by any chance?

Read our AI policy: https://palletsprojects.com/contributing/llm-ai

ThiefMaster avatar Sep 24 '26 15:09 ThiefMaster