Coverage for /usr/local/lib/python3.12/site-packages/prefect/utilities/text.py: 38%
17 statements
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 10:48 +0000
« prev ^ index » next coverage.py v7.10.6, created at 2025-12-05 10:48 +0000
1import difflib 1a
2from collections.abc import Iterable 1a
3from typing import Optional 1a
6def truncated_to(length: int, value: Optional[str]) -> str: 1a
7 if not value: 7 ↛ 10line 7 didn't jump to line 10 because the condition on line 7 was always true1bc
8 return "" 1bc
10 if len(value) <= length:
11 return value
13 half = length // 2
15 beginning = value[:half]
16 end = value[-half:]
17 omitted = len(value) - (len(beginning) + len(end))
19 proposed = f"{beginning}...{omitted} additional characters...{end}"
21 return proposed if len(proposed) < len(value) else value
24def fuzzy_match_string( 1a
25 word: str,
26 possibilities: Iterable[str],
27 *,
28 n: int = 1,
29 cutoff: float = 0.6,
30) -> Optional[str]:
31 match = difflib.get_close_matches(word, possibilities, n=n, cutoff=cutoff)
32 return match[0] if match else None