* 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)
| 4938 | * ceiling, and the project's own modules with it. |
| 4939 | */ |
| 4940 | function pythonImportBindingTail(ref: UnresolvedRef, context: ResolutionContext): string | undefined { |
| 4941 | if (!IDENTIFIER.test(ref.referenceName)) return undefined; |
| 4942 | const binding = context.getImportMappings(ref.filePath, 'python').find((m) => m.localName === ref.referenceName); |
| 4943 | if (!binding || isExternalImport(binding.source, 'python', context)) return undefined; |
| 4944 | const declared = binding.isNamespace ? binding.source.slice(binding.source.lastIndexOf('.') + 1) : binding.exportedName; |
| 4945 | if (declared === binding.localName && (binding.isNamespace || !isProjectPythonModule(binding.source, context))) return undefined; |
| 4946 | const modulePath = pythonModulePath(binding.source, ref.filePath); |
| 4947 | return modulePath ? moduleTail(modulePath) || undefined : undefined; |
| 4948 | } |
| 4949 | |
| 4950 | /** |
| 4951 | * Whether a Python import's module is in one of the project's own folders: a |
no test coverage detected