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

Function resolvePythonAbsoluteModule

src/resolution/import-resolver.ts:4174–4189  ·  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

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