MCPcopy
hub / github.com/python/mypy / find_node

Function find_node

mypy/inspections.py:87–106  ·  view source on GitHub ↗

Find the node defining member 'name' in given TypeInfo.

(name: str, info: TypeInfo)

Source from the content-addressed store, hash-verified

85
86
87def find_node(name: str, info: TypeInfo) -> Var | FuncBase | None:
88 """Find the node defining member 'name' in given TypeInfo."""
89 # TODO: this code shares some logic with checkmember.py
90 method = info.get_method(name)
91 if method:
92 if isinstance(method, Decorator):
93 return method.var
94 if method.is_property:
95 assert isinstance(method, OverloadedFuncDef)
96 dec = method.items[0]
97 assert isinstance(dec, Decorator)
98 return dec.var
99 return method
100 else:
101 # don't have such method, maybe variable?
102 node = info.get(name)
103 v = node.node if node else None
104 if isinstance(v, Var):
105 return v
106 return None
107
108
109def find_module_by_fullname(fullname: str, modules: dict[str, State]) -> State | None:

Callers 1

collect_nodesMethod · 0.85

Calls 3

isinstanceFunction · 0.85
get_methodMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…