* 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)
| 3967 | * nothing under it and star-imports no module that might export it. |
| 3968 | */ |
| 3969 | private isUnboundPythonBuiltin(ref: UnresolvedRef): boolean { |
| 3970 | const line = (this.context.getFileLines?.(ref.filePath) ?? this.context.readFile(ref.filePath)?.split(/\r?\n/))?.[ref.line - 1]; |
| 3971 | if (line === undefined || !line.startsWith(ref.referenceName, ref.column) || /\.\s*$/.test(line.slice(0, ref.column))) return false; |
| 3972 | let file = this.pythonFileBindings; |
| 3973 | if (file?.filePath !== ref.filePath) { |
| 3974 | const names = new Set(this.context.getNodesInFile(ref.filePath).map((n) => n.name)); |
| 3975 | for (const m of this.context.getImportMappings(ref.filePath, 'python')) names.add(m.localName); |
| 3976 | const star = /^[ \t]*from[ \t]+[\w.]+[ \t]+import[ \t(]*\*/m.test(this.context.readFile(ref.filePath) ?? ''); |
| 3977 | this.pythonFileBindings = file = { filePath: ref.filePath, names, star }; |
| 3978 | } |
| 3979 | return !file.star && !file.names.has(ref.referenceName); |
| 3980 | } |
| 3981 | |
| 3982 | /** |
| 3983 | * True when the Go file imports `qualifier` — by its last path segment or |
no test coverage detected