MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / resolvePythonAbsoluteModule

Function resolvePythonAbsoluteModule

src/resolution/import-resolver.ts:4173–4188  ·  view source on GitHub ↗

* Resolve a Python dotted module import (`import a.b.c`, `from .a.b import x`) to its file — * the Django `AppConfig.ready(): import myapp.signals` pattern and any * side-effect module import.

(
  ref: UnresolvedRef,
  context: ResolutionContext
)

Source from the content-addressed store, hash-verified

4171 * side-effect module import.
4172 */
4173function resolvePythonAbsoluteModule(
4174 ref: UnresolvedRef,
4175 context: ResolutionContext
4176): ResolvedRef | null {
4177 if (ref.referenceKind !== 'imports') return null;
4178 // Only a DOTTED `import a.b.c` ref carries its full module path, and so does
4179 // the module a from-import names, dotted or not: `from loader import X` is
4180 // the top-level `loader`, found from the package roots as `import loader`
4181 // finds it. A bare leaf it imports (`from app.api.routes import
4182 // authentication`) is ambiguous on its own — three `authentication.py` files
4183 // may exist — so leave it to resolveModuleImportToFile, which uses the
4184 // import's source (`app.api.routes`) to build the full path.
4185 if (!ref.referenceName.includes('.') && !isPythonFromImportModule(ref, context)) return null;
4186 const hit = pythonModuleFileNode(ref.referenceName, ref.filePath, context);
4187 return hit ? { original: ref, targetNodeId: hit.id, confidence: 0.9, resolvedBy: 'import' } : null;
4188}
4189
4190/**
4191 * Resolve a Rust qualified reference `A::B::C` to the item module `A::B`

Callers 1

resolveViaImportFunction · 0.85

Calls 1

pythonModuleFileNodeFunction · 0.85

Tested by

no test coverage detected