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

Method isPythonProjectModule

src/resolution/index.ts:3665–3686  ·  view source on GitHub ↗

* True when `receiver` is a local name bound by an import that resolves to a * file IN THIS PROJECT — the only case where letting a python * built-in-method name through the filter is safe (#1681). * * Asking only whether SOME import bound the local name is not enough: every * import

(ref: UnresolvedRef, receiver: string)

Source from the content-addressed store, hash-verified

3663 * stays filtered.
3664 */
3665 private isPythonProjectModule(ref: UnresolvedRef, receiver: string): boolean {
3666 const imports = this.context.getImportMappings(ref.filePath, ref.language);
3667 if (!imports.some((imp) => imp.localName === receiver)) return false;
3668 const local = pythonFunctionModuleAlias(receiver, ref, this.context);
3669 if (local) return resolveImportPath(local, ref.filePath, ref.language!, this.context) !== null;
3670 for (const imp of pythonImportsInScope(ref, imports, this.context)) {
3671 if (imp.localName !== receiver) continue;
3672 // `import pkg.mod` / `import pkg.mod as m` binds the module `source`
3673 // names. `from pkg import mod` binds `pkg.mod`, and `from . import mod`
3674 // binds `.mod` — join without doubling the dot that makes `.` mean the
3675 // current package.
3676 const specifier = imp.isNamespace
3677 ? imp.source
3678 : imp.source.endsWith('.')
3679 ? `${imp.source}${imp.exportedName}`
3680 : `${imp.source}.${imp.exportedName}`;
3681 if (resolveImportPath(specifier, ref.filePath, ref.language!, this.context)) {
3682 return true;
3683 }
3684 }
3685 return false;
3686 }
3687
3688 /** A python call `x.get(…)` of a method named like a builtin collection, string or file method. */
3689 private isPythonBuiltinNamedMethodCall(ref: UnresolvedRef): boolean {

Callers 1

isBuiltInOrExternalMethod · 0.95

Calls 3

resolveImportPathFunction · 0.90
pythonImportsInScopeFunction · 0.90
getImportMappingsMethod · 0.80

Tested by

no test coverage detected