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

Function get_dependencies_of_target

mypy/server/deps.py:192–217  ·  view source on GitHub ↗

Get dependencies of a target -- don't recursive into nested targets.

(
    module_id: str,
    module_tree: MypyFile,
    target: Node,
    type_map: dict[Expression, Type],
    python_version: tuple[int, int],
)

Source from the content-addressed store, hash-verified

190
191
192def get_dependencies_of_target(
193 module_id: str,
194 module_tree: MypyFile,
195 target: Node,
196 type_map: dict[Expression, Type],
197 python_version: tuple[int, int],
198) -> dict[str, set[str]]:
199 """Get dependencies of a target -- don't recursive into nested targets."""
200 # TODO: Add tests for this function.
201 visitor = DependencyVisitor(type_map, python_version, module_tree.alias_deps)
202 with visitor.scope.module_scope(module_id):
203 if isinstance(target, MypyFile):
204 # Only get dependencies of the top-level of the module. Don't recurse into
205 # functions.
206 for defn in target.defs:
207 # TODO: Recurse into top-level statements and class bodies but skip functions.
208 if not isinstance(defn, (ClassDef, Decorator, FuncDef, OverloadedFuncDef)):
209 defn.accept(visitor)
210 elif isinstance(target, FuncBase) and target.info:
211 # It's a method.
212 # TODO: Methods in nested classes.
213 with visitor.scope.class_scope(target.info):
214 target.accept(visitor)
215 else:
216 target.accept(visitor)
217 return visitor.map
218
219
220class DependencyVisitor(TraverserVisitor):

Callers 1

update_depsFunction · 0.90

Calls 5

DependencyVisitorClass · 0.85
isinstanceFunction · 0.85
module_scopeMethod · 0.80
class_scopeMethod · 0.80
acceptMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…