Function to correct for relative imports.
(self, file: MypyFile, imp: ImportFrom | ImportAll)
| 1187 | return int(self.metastore.getmtime(path)) |
| 1188 | |
| 1189 | def correct_rel_imp(self, file: MypyFile, imp: ImportFrom | ImportAll) -> str: |
| 1190 | """Function to correct for relative imports.""" |
| 1191 | file_id = file.fullname |
| 1192 | rel = imp.relative |
| 1193 | if rel == 0: |
| 1194 | return imp.id |
| 1195 | if os.path.basename(file.path).startswith("__init__."): |
| 1196 | rel -= 1 |
| 1197 | if rel != 0: |
| 1198 | file_id = ".".join(file_id.split(".")[:-rel]) |
| 1199 | new_id = file_id + "." + imp.id if imp.id else file_id |
| 1200 | |
| 1201 | if not new_id: |
| 1202 | self.errors.set_file(file.path, file.name, self.options) |
| 1203 | self.error( |
| 1204 | imp.line, "No parent module -- cannot perform relative import", blocker=True |
| 1205 | ) |
| 1206 | |
| 1207 | return new_id |
| 1208 | |
| 1209 | def all_imported_modules_in_file(self, file: MypyFile) -> list[tuple[int, str, int]]: |
| 1210 | """Find all reachable import statements in a file. |
no test coverage detected