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

Function pythonImportBindingTail

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

4938 * ceiling, and the project's own modules with it.
4939 */
4940function pythonImportBindingTail(ref: UnresolvedRef, context: ResolutionContext): string | undefined {
4941 if (!IDENTIFIER.test(ref.referenceName)) return undefined;
4942 const binding = context.getImportMappings(ref.filePath, 'python').find((m) => m.localName === ref.referenceName);
4943 if (!binding || isExternalImport(binding.source, 'python', context)) return undefined;
4944 const declared = binding.isNamespace ? binding.source.slice(binding.source.lastIndexOf('.') + 1) : binding.exportedName;
4945 if (declared === binding.localName && (binding.isNamespace || !isProjectPythonModule(binding.source, context))) return undefined;
4946 const modulePath = pythonModulePath(binding.source, ref.filePath);
4947 return modulePath ? moduleTail(modulePath) || undefined : undefined;
4948}
4949
4950/**
4951 * 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