* 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)
| 3851 | * stays filtered. |
| 3852 | */ |
| 3853 | private isPythonProjectModule(ref: UnresolvedRef, receiver: string): boolean { |
| 3854 | const imports = this.context.getImportMappings(ref.filePath, ref.language); |
| 3855 | if (!imports.some((imp) => imp.localName === receiver)) return false; |
| 3856 | const local = pythonFunctionModuleAlias(receiver, ref, this.context); |
| 3857 | if (local) return resolveImportPath(local, ref.filePath, ref.language!, this.context) !== null; |
| 3858 | for (const imp of pythonImportsInScope(ref, imports, this.context)) { |
| 3859 | if (imp.localName !== receiver) continue; |
| 3860 | // `import pkg.mod` / `import pkg.mod as m` binds the module `source` |
| 3861 | // names. `from pkg import mod` binds `pkg.mod`, and `from . import mod` |
| 3862 | // binds `.mod` — join without doubling the dot that makes `.` mean the |
| 3863 | // current package. |
| 3864 | const specifier = imp.isNamespace |
| 3865 | ? imp.source |
| 3866 | : imp.source.endsWith('.') |
| 3867 | ? `${imp.source}${imp.exportedName}` |
| 3868 | : `${imp.source}.${imp.exportedName}`; |
| 3869 | if (resolveImportPath(specifier, ref.filePath, ref.language!, this.context)) { |
| 3870 | return true; |
| 3871 | } |
| 3872 | } |
| 3873 | return false; |
| 3874 | } |
| 3875 | |
| 3876 | /** A python call `x.get(…)` of a method named like a builtin collection, string or file method. */ |
| 3877 | private isPythonBuiltinNamedMethodCall(ref: UnresolvedRef): boolean { |
no test coverage detected