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

Method get_guesses_from_parent

mypy/suggestions.py:461–476  ·  view source on GitHub ↗

Try to get a guess of a method type from a parent class.

(self, node: FuncDef)

Source from the content-addressed store, hash-verified

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.

Callers 1

get_suggestionMethod · 0.95

Calls 4

get_proper_typeFunction · 0.90
isinstanceFunction · 0.85
lenFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected