* 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)
| 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 |
no test coverage detected