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

Method find_best

mypy/suggestions.py:450–459  ·  view source on GitHub ↗

From a list of possible function types, find the best one. For best, we want the fewest errors, then the best "score" from score_callable.

(self, func: FuncDef, guesses: list[CallableType])

Source from the content-addressed store, hash-verified

448 ]
449
450 def find_best(self, func: FuncDef, guesses: list[CallableType]) -> tuple[CallableType, int]:
451 """From a list of possible function types, find the best one.
452
453 For best, we want the fewest errors, then the best "score" from score_callable.
454 """
455 if not guesses:
456 raise SuggestionFailure("No guesses that match criteria!")
457 errors = {guess: self.try_type(func, guess) for guess in guesses}
458 best = min(guesses, key=lambda s: (count_errors(errors[s]), self.score_callable(s)))
459 return best, count_errors(errors[best])
460
461 def get_guesses_from_parent(self, node: FuncDef) -> list[CallableType]:
462 """Try to get a guess of a method type from a parent class."""

Callers 1

get_suggestionMethod · 0.95

Calls 5

try_typeMethod · 0.95
score_callableMethod · 0.95
SuggestionFailureClass · 0.85
minFunction · 0.85
count_errorsFunction · 0.85

Tested by

no test coverage detected