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

Function pythonImportBindingTail

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

* importBindingTail for Python: `from .models import User as * UserModel` and `from . import helpers as h` bind a name their module has as * `User` and `helpers`, `import app.tools as tl` one it has as `tools`. The * module is the one the import names by its dotted path, counted from the

(ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

4716 * ceiling, and the project's own modules with it.
4717 */
4718function pythonImportBindingTail(ref: UnresolvedRef, context: ResolutionContext): string | undefined {
4719 if (!IDENTIFIER.test(ref.referenceName)) return undefined;
4720 const binding = context.getImportMappings(ref.filePath, 'python').find((m) => m.localName === ref.referenceName);
4721 if (!binding || isExternalImport(binding.source, 'python', context)) return undefined;
4722 const declared = binding.isNamespace ? binding.source.slice(binding.source.lastIndexOf('.') + 1) : binding.exportedName;
4723 if (declared === binding.localName && (binding.isNamespace || !isProjectPythonModule(binding.source, context))) return undefined;
4724 const modulePath = pythonModulePath(binding.source, ref.filePath);
4725 return modulePath ? moduleTail(modulePath) || undefined : undefined;
4726}
4727
4728/**
4729 * Whether a Python import's module is in one of the project's own folders: a

Callers 1

importBindingTailFunction · 0.85

Calls 5

moduleTailFunction · 0.90
isExternalImportFunction · 0.85
isProjectPythonModuleFunction · 0.85
pythonModulePathFunction · 0.85
getImportMappingsMethod · 0.80

Tested by

no test coverage detected