* importBindingTail for Python: `from .models import User as * UserModel` and `from . import helpers as h` bind a name their module has as * `User` and `helpers`, `import app.tools as tl` one it has as `tools`. The * module is the one the import names by its dotted path, counted from the
(ref: UnresolvedRef, context: ResolutionContext)
| 4716 | * ceiling, and the project's own modules with it. |
| 4717 | */ |
| 4718 | function pythonImportBindingTail(ref: UnresolvedRef, context: ResolutionContext): string | undefined { |
| 4719 | if (!IDENTIFIER.test(ref.referenceName)) return undefined; |
| 4720 | const binding = context.getImportMappings(ref.filePath, 'python').find((m) => m.localName === ref.referenceName); |
| 4721 | if (!binding || isExternalImport(binding.source, 'python', context)) return undefined; |
| 4722 | const declared = binding.isNamespace ? binding.source.slice(binding.source.lastIndexOf('.') + 1) : binding.exportedName; |
| 4723 | if (declared === binding.localName && (binding.isNamespace || !isProjectPythonModule(binding.source, context))) return undefined; |
| 4724 | const modulePath = pythonModulePath(binding.source, ref.filePath); |
| 4725 | return modulePath ? moduleTail(modulePath) || undefined : undefined; |
| 4726 | } |
| 4727 | |
| 4728 | /** |
| 4729 | * Whether a Python import's module is in one of the project's own folders: a |
no test coverage detected