( context: ResolutionContext, editedFiles: string[] )
| 1078 | * the module has: `from types import ModuleType` beside `mypy/types.py` never does. |
| 1079 | */ |
| 1080 | export function pythonScriptModuleScope( |
| 1081 | context: ResolutionContext, |
| 1082 | editedFiles: string[] |
| 1083 | ): { targetFiles: string[]; sourceDirs: string[]; moduleLeaves: string[] } { |
| 1084 | const index = pythonModuleIndex(context); |
| 1085 | const targetFiles: string[] = []; |
| 1086 | const moduleLeaves: string[] = []; |
| 1087 | for (const raw of editedFiles) { |
| 1088 | const file = raw.replace(/\\/g, '/'); |
| 1089 | if (!PYTHON_MODULE_FILE.test(file)) continue; |
| 1090 | const mod = file.replace(/(?:^|\/)__init__\.py$/, '').replace(/\.py$/, ''); |
| 1091 | for (let dir = parentDir(mod); dir; dir = parentDir(dir)) { |
| 1092 | const specifier = mod.slice(dir.length + 1).replace(/\//g, '.'); |
| 1093 | if (PYTHON_STDLIB_MODULES.has(specifier.split('.')[0]!)) continue; |
| 1094 | const importers = context.getNodesByName(specifier) |
| 1095 | .filter((n) => n.kind === 'import' && PYTHON_MODULE_FILE.test(n.filePath)) |
| 1096 | .map((n) => parentDir(n.filePath)); |
| 1097 | const reached = index.packageDirs.has(dir) |
| 1098 | ? importers.includes(dir) |
| 1099 | : !index.projectRoots.has(dir) && !index.localRoots.has(dir) && |
| 1100 | importers.some((d) => d.startsWith(`${dir}/`)); |
| 1101 | if (!reached) continue; |
| 1102 | targetFiles.push(file); |
| 1103 | moduleLeaves.push(mod.slice(mod.lastIndexOf('/') + 1)); |
| 1104 | break; |
| 1105 | } |
| 1106 | } |
| 1107 | return { targetFiles, sourceDirs: [], moduleLeaves }; |
| 1108 | } |
| 1109 | |
| 1110 | /** |
| 1111 | * The Python files that import one of the packages whose `__init__.py` is in |
no test coverage detected