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

Function pythonImportBindingTail

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

4939 * ceiling, and the project's own modules with it.
4940 */
4941function pythonImportBindingTail(ref: UnresolvedRef, context: ResolutionContext): string | undefined {
4942 if (!IDENTIFIER.test(ref.referenceName)) return undefined;
4943 const binding = importsBoundTo(context.getImportMappings(ref.filePath, 'python'), ref.referenceName)[0];
4944 if (!binding || isExternalImport(binding.source, 'python', context)) return undefined;
4945 const declared = binding.isNamespace ? binding.source.slice(binding.source.lastIndexOf('.') + 1) : binding.exportedName;
4946 if (declared === binding.localName && (binding.isNamespace || !isProjectPythonModule(binding.source, context))) return undefined;
4947 const modulePath = pythonModulePath(binding.source, ref.filePath);
4948 return modulePath ? moduleTail(modulePath) || undefined : undefined;
4949}
4950
4951/**
4952 * Whether a Python import's module is in one of the project's own folders: a

Callers 1

importBindingTailFunction · 0.85

Calls 6

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

Tested by

no test coverage detected