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