Skip to content

Commit

Permalink
use max over sort
Browse files Browse the repository at this point in the history
  • Loading branch information
willmcgugan committed Dec 10, 2024
1 parent cc5fa9e commit 924765f
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/textual/fuzzy.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,9 @@ def match(self, query: str, candidate: str) -> tuple[float, tuple[int, ...]]:
cache_key = (query, candidate, self.case_sensitive)
if cache_key in self.cache:
return self.cache[cache_key]

matches = sorted(self._match(query, candidate), key=itemgetter(0))
result: tuple[float, tuple[int, ...]]
if not matches:
result = (0.0, ())
else:
result = matches[-1]
result = max(
self._match(query, candidate), key=itemgetter(0), default=(0.0, ())
)
self.cache[cache_key] = result
return result

Expand Down

0 comments on commit 924765f

Please sign in to comment.