Try to get a guess of a method type from a parent class.
(self, node: FuncDef)
| 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.""" |
| 463 | if not node.info: |
| 464 | return [] |
| 465 | |
| 466 | for parent in node.info.mro[1:]: |
| 467 | pnode = parent.names.get(node.name) |
| 468 | if pnode and isinstance(pnode.node, (FuncDef, Decorator)): |
| 469 | typ = get_proper_type(pnode.node.type) |
| 470 | # FIXME: Doesn't work right with generic types |
| 471 | if isinstance(typ, CallableType) and len(typ.arg_types) == len(node.arguments): |
| 472 | # Return the first thing we find, since it probably doesn't make sense |
| 473 | # to grab things further up in the chain if an earlier parent has it. |
| 474 | return [typ] |
| 475 | |
| 476 | return [] |
| 477 | |
| 478 | def get_suggestion(self, mod: str, node: FuncDef) -> PyAnnotateSignature: |
| 479 | """Compute a suggestion for a function. |
no test coverage detected