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

Function pythonPackageBinds

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

* Whether `from P import N` binds something `P/__init__.py` defines or * re-exports, rather than the submodule `P.N`. CPython's `_handle_fromlist` * looks `N` up as an attribute of the package first and imports the * submodule only when the package has no such attribute — so a def, a * constant

(imp: ImportMapping, fromFile: string, context: ResolutionContext)

Source from the content-addressed store, hash-verified

4016 * answer, as before.
4017 */
4018function pythonPackageBinds(imp: ImportMapping, fromFile: string, context: ResolutionContext): boolean {
4019 if (imp.isNamespace || imp.exportedName === '*') return false;
4020 const packageFile = resolveImportPath(imp.source, fromFile, 'python', context);
4021 if (!packageFile || !/(?:^|\/)__init__\.py$/.test(packageFile)) return false;
4022 return (
4023 findExportedSymbol(
4024 packageFile,
4025 { isDefault: false, isNamespace: false, exportedName: imp.exportedName, memberName: null },
4026 'python',
4027 context,
4028 new Set()
4029 ) !== undefined
4030 );
4031}
4032
4033/**
4034 * Resolve a whole-MODULE import to that module's file (a file→file dependency).

Callers 2

Calls 2

resolveImportPathFunction · 0.85
findExportedSymbolFunction · 0.85

Tested by

no test coverage detected