`Matcher(case_sensitive=True)` still matches case-insensitively

Open Beginner friendly
#6,775 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
80/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
python
Domain
backend

Research direction

Both classes live in the textual.fuzzy module: start in Matcher.__init__, where the FuzzySearch is built without forwarding case_sensitive, then read FuzzySearch.match and its result cache, whose key ignores the flag. Reproduce with the snippet in the issue, make the cache respect case_sensitive (key it, or clear it when the attribute changes), and confirm Matcher("foo", case_sensitive=True).match("FOO") returns 0.0 while the insensitive search still returns 16.0.

Written by the indexing model from the issue text.

Description

Hi! I hit this while writing generated tests against Textual's widgets.

Matcher stores case_sensitive but makes its FuzzySearch with the default, so the setting has no effect. That also means Provider.matcher(user_input, case_sensitive=True) in a command palette provider is case-insensitive. Separately, FuzzySearch caches results by (query, candidate) only, so changing its case_sensitive attribute keeps returning the old results.

from textual.fuzzy import FuzzySearch, Matcher

matcher = Matcher("foo", case_sensitive=True)
print("Matcher(case_sensitive=True).match('FOO'):", matcher.match("FOO"))
print("matcher.fuzzy_search.case_sensitive:", matcher.fuzzy_search.case_sensitive)

search = FuzzySearch()
print("insensitive:", search.match("foo", "FOO"))
search.case_sensitive = True
print("after case_sensitive = True:", search.match("foo", "FOO"))
print("fresh FuzzySearch(case_sensitive=True):", FuzzySearch(case_sensitive=True).match("foo", "FOO"))

Output (the same on 8.2.7 and on main at 5e5b7ef):

Matcher(case_sensitive=True).match('FOO'): 16.0
matcher.fuzzy_search.case_sensitive: False
insensitive: (16.0, [0, 1, 2])
after case_sensitive = True: (16.0, [0, 1, 2])
fresh FuzzySearch(case_sensitive=True): (0.0, ())

I'd expect the first line to be 0.0, and the fourth to match the fifth.

Textual 8.2.7 and main (5e5b7ef), Python 3.13, macOS.

Dominant language
Python
Stars
37.7k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Textualize/textual

All issues in Textualize/textual

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.