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

Method isPythonProjectModule

src/resolution/index.ts:3935–3956  ·  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

3933 * stays filtered.
3934 */
3935 private isPythonProjectModule(ref: UnresolvedRef, receiver: string): boolean {
3936 const imports = this.context.getImportMappings(ref.filePath, ref.language);
3937 if (!imports.some((imp) => imp.localName === receiver)) return false;
3938 const local = pythonFunctionModuleAlias(receiver, ref, this.context);
3939 if (local) return resolveImportPath(local, ref.filePath, ref.language!, this.context) !== null;
3940 for (const imp of pythonImportsInScope(ref, imports, this.context)) {
3941 if (imp.localName !== receiver) continue;
3942 // `import pkg.mod` / `import pkg.mod as m` binds the module `source`
3943 // names. `from pkg import mod` binds `pkg.mod`, and `from . import mod`
3944 // binds `.mod` — join without doubling the dot that makes `.` mean the
3945 // current package.
3946 const specifier = imp.isNamespace
3947 ? imp.source
3948 : imp.source.endsWith('.')
3949 ? `${imp.source}${imp.exportedName}`
3950 : `${imp.source}.${imp.exportedName}`;
3951 if (resolveImportPath(specifier, ref.filePath, ref.language!, this.context)) {
3952 return true;
3953 }
3954 }
3955 return false;
3956 }
3957
3958 /** A python call `x.get(…)` of a method named like a builtin collection, string or file method. */
3959 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