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

Method get_suggestion

mypy/suggestions.py:478–520  ·  view source on GitHub ↗

Compute a suggestion for a function. Return the type and whether the first argument should be ignored.

(self, mod: str, node: FuncDef)

Source from the content-addressed store, hash-verified

476 return []
477
478 def get_suggestion(self, mod: str, node: FuncDef) -> PyAnnotateSignature:
479 """Compute a suggestion for a function.
480
481 Return the type and whether the first argument should be ignored.
482 """
483 graph = self.graph
484 callsites, orig_errors = self.get_callsites(node)
485 uses = get_arg_uses(self.manager.all_types, node)
486
487 if self.no_errors and orig_errors:
488 raise SuggestionFailure("Function does not typecheck.")
489
490 is_method = bool(node.info) and node.has_self_or_cls_argument
491
492 with state.strict_optional_set(graph[mod].options.strict_optional):
493 guesses = self.get_guesses(
494 is_method,
495 self.get_starting_type(node),
496 self.get_default_arg_types(node),
497 callsites,
498 uses,
499 )
500 guesses += self.get_guesses_from_parent(node)
501 guesses = self.filter_options(guesses, is_method, ignore_return=True)
502 best, _ = self.find_best(node, guesses)
503
504 # Now try to find the return type!
505 self.try_type(node, best)
506 returns = get_return_types(self.manager.all_types, node)
507 with state.strict_optional_set(graph[mod].options.strict_optional):
508 if returns:
509 ret_types = generate_type_combinations(returns)
510 else:
511 ret_types = [NoneType()]
512
513 guesses = [best.copy_modified(ret_type=refine_type(best.ret_type, t)) for t in ret_types]
514 guesses = self.filter_options(guesses, is_method, ignore_return=False)
515 best, errors = self.find_best(node, guesses)
516
517 if self.no_errors and errors:
518 raise SuggestionFailure("No annotation without errors")
519
520 return self.pyannotate_signature(mod, is_method, best)
521
522 def format_args(
523 self,

Callers 1

suggestMethod · 0.95

Calls 15

get_callsitesMethod · 0.95
get_guessesMethod · 0.95
get_starting_typeMethod · 0.95
get_default_arg_typesMethod · 0.95
filter_optionsMethod · 0.95
find_bestMethod · 0.95
try_typeMethod · 0.95
pyannotate_signatureMethod · 0.95
NoneTypeClass · 0.90
get_arg_usesFunction · 0.85
SuggestionFailureClass · 0.85

Tested by

no test coverage detected