* The file's import mappings as a bare Python name reads them (#3229). The * mappings read from-imports at any depth, so `from pkg.core import reverts` * written inside one function was the whole file's, and every other call of * `reverts` linked the import, though the file's own `def reverts` is
(ref: UnresolvedRef, imports: ImportMapping[], context: ResolutionContext)
| 3866 | * binding other than an import, and the module's own imports, change nothing. |
| 3867 | */ |
| 3868 | function pythonBareImportsInScope(ref: UnresolvedRef, imports: ImportMapping[], context: ResolutionContext): ImportMapping[] { |
| 3869 | const name = ref.referenceName; |
| 3870 | const binds = (m: ImportMapping): boolean => m.localName === name; |
| 3871 | if (!imports.some(binds)) return imports; |
| 3872 | const local = pythonFunctionImportKeys(name, ref.filePath, context); |
| 3873 | if (local.size === 0) return imports; |
| 3874 | const keyOf = (m: ImportMapping): string => (m.isNamespace ? `${m.source}:*` : `${m.source}:${m.exportedName}`); |
| 3875 | const binding = pythonReceiverBinding(name, ref, context); |
| 3876 | if (binding === 'module') { |
| 3877 | const moduleLevel = pythonModuleImportKeys(name, ref.filePath, context); |
| 3878 | return imports.filter((m) => !binds(m) || moduleLevel.has(keyOf(m)) || !local.has(keyOf(m))); |
| 3879 | } |
| 3880 | if (binding === 'local' || 'module' in binding) return imports; |
| 3881 | return imports.filter((m) => !binds(m) || (!m.isNamespace && m.source === binding.source && m.exportedName === binding.exportedName)); |
| 3882 | } |
| 3883 | |
| 3884 | /** |
| 3885 | * Resolve a Python qualified reference whose receiver is an imported MODULE: |
no test coverage detected