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

Method isUnboundPythonBuiltin

src/resolution/index.ts:3897–3908  ·  view source on GitHub ↗

* Whether a Python reference to a builtin's name (PYTHON_BUILTIN_NAMES) can * only mean the builtin: written bare (`self.format()` and `errors.Timeout` * name a member), in a file that defines nothing of that name, imports * nothing under it and star-imports no module that might export it.

(ref: UnresolvedRef)

Source from the content-addressed store, hash-verified

3895 * nothing under it and star-imports no module that might export it.
3896 */
3897 private isUnboundPythonBuiltin(ref: UnresolvedRef): boolean {
3898 const line = (this.context.getFileLines?.(ref.filePath) ?? this.context.readFile(ref.filePath)?.split(/\r?\n/))?.[ref.line - 1];
3899 if (line === undefined || !line.startsWith(ref.referenceName, ref.column) || /\.\s*$/.test(line.slice(0, ref.column))) return false;
3900 let file = this.pythonFileBindings;
3901 if (file?.filePath !== ref.filePath) {
3902 const names = new Set(this.context.getNodesInFile(ref.filePath).map((n) => n.name));
3903 for (const m of this.context.getImportMappings(ref.filePath, 'python')) names.add(m.localName);
3904 const star = /^[ \t]*from[ \t]+[\w.]+[ \t]+import[ \t(]*\*/m.test(this.context.readFile(ref.filePath) ?? '');
3905 this.pythonFileBindings = file = { filePath: ref.filePath, names, star };
3906 }
3907 return !file.star && !file.names.has(ref.referenceName);
3908 }
3909
3910 /**
3911 * True when the Go file imports `qualifier` — by its last path segment or

Callers 1

isBuiltInOrExternalMethod · 0.95

Calls 7

getFileLinesMethod · 0.80
mapMethod · 0.80
getImportMappingsMethod · 0.80
hasMethod · 0.80
readFileMethod · 0.65
getNodesInFileMethod · 0.65
addMethod · 0.45

Tested by

no test coverage detected