MCPcopy Create free account
hub / github.com/python/mypy / _lookup_target_impl

Function _lookup_target_impl

mypy/server/update.py:1125–1193  ·  view source on GitHub ↗
(
    manager: BuildManager, target: str
)

Source from the content-addressed store, hash-verified

1123
1124
1125def _lookup_target_impl(
1126 manager: BuildManager, target: str
1127) -> tuple[list[FineGrainedDeferredNode], TypeInfo | None]:
1128 def not_found() -> None:
1129 manager.log_fine_grained(f"Can't find matching target for {target} (stale dependency?)")
1130
1131 modules = manager.modules
1132 items = split_target(modules, target)
1133 if items is None:
1134 not_found() # Stale dependency
1135 return [], None
1136 module, rest = items
1137 if rest:
1138 components = rest.split(".")
1139 else:
1140 components = []
1141 node: SymbolNode | None = modules[module]
1142 file: MypyFile | None = None
1143 active_class = None
1144 for c in components:
1145 if isinstance(node, TypeInfo):
1146 active_class = node
1147 if isinstance(node, MypyFile):
1148 file = node
1149 if not isinstance(node, (MypyFile, TypeInfo)) or c not in node.names:
1150 not_found() # Stale dependency
1151 return [], None
1152 # Don't reprocess plugin generated targets. They should get
1153 # stripped and regenerated when the containing target is
1154 # reprocessed.
1155 if node.names[c].plugin_generated:
1156 return [], None
1157 node = node.names[c].node
1158 if isinstance(node, TypeInfo):
1159 # A ClassDef target covers the body of the class and everything defined
1160 # within it. To get the body we include the entire surrounding target,
1161 # typically a module top-level, since we don't support processing class
1162 # bodies as separate entities for simplicity.
1163 assert file is not None
1164 if node.fullname != target:
1165 # This is a reference to a different TypeInfo, likely due to a stale dependency.
1166 # Processing them would spell trouble -- for example, we could be refreshing
1167 # a deserialized TypeInfo with missing attributes.
1168 not_found()
1169 return [], None
1170 result = [FineGrainedDeferredNode(file, None)]
1171 stale_info: TypeInfo | None = None
1172 if node.is_protocol:
1173 stale_info = node
1174 for name, symnode in node.names.items():
1175 node = symnode.node
1176 if isinstance(node, FuncDef):
1177 method, _ = _lookup_target_impl(manager, target + "." + name)
1178 result.extend(method)
1179 return result, stale_info
1180 if isinstance(node, Decorator):
1181 # Decorator targets actually refer to the function definition only.
1182 node = node.func

Callers 1

lookup_targetFunction · 0.85

Calls 7

split_targetFunction · 0.90
not_foundFunction · 0.85
isinstanceFunction · 0.85
splitMethod · 0.80
extendMethod · 0.80
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…