Compute a suggestion for a function. Return the type and whether the first argument should be ignored.
(self, mod: str, node: FuncDef)
| 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, |
no test coverage detected