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],
)
| 190 | |
| 191 | |
| 192 | def 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 | |
| 220 | class DependencyVisitor(TraverserVisitor): |
no test coverage detected
searching dependent graphs…