MCPcopy Index your code
hub / github.com/python/mypy / best_matches

Function best_matches

mypy/messages.py:3376–3386  ·  view source on GitHub ↗
(current: str, options: Collection[str], n: int)

Source from the content-addressed store, hash-verified

3374
3375
3376def best_matches(current: str, options: Collection[str], n: int) -> list[str]:
3377 if not current:
3378 return []
3379 # narrow down options cheaply
3380 options = [o for o in options if _real_quick_ratio(current, o) > 0.75]
3381 if len(options) >= 50:
3382 options = [o for o in options if abs(len(o) - len(current)) <= 1]
3383
3384 ratios = {option: difflib.SequenceMatcher(a=current, b=option).ratio() for option in options}
3385 options = [option for option, ratio in ratios.items() if ratio > 0.75]
3386 return sorted(options, key=lambda v: (-ratios[v], v))[:n]
3387
3388
3389def pretty_seq(args: Sequence[str], conjunction: str) -> str:

Callers 7

module_not_foundFunction · 0.90
name_not_definedMethod · 0.90
has_no_attrMethod · 0.85

Calls 5

_real_quick_ratioFunction · 0.85
lenFunction · 0.85
absFunction · 0.85
sortedFunction · 0.85
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…