MCPcopy Index your code
hub / github.com/python/mypy / correct_rel_imp

Method correct_rel_imp

mypy/build.py:1189–1207  ·  view source on GitHub ↗

Function to correct for relative imports.

(self, file: MypyFile, imp: ImportFrom | ImportAll)

Source from the content-addressed store, hash-verified

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.

Callers 1

Calls 5

errorMethod · 0.95
splitMethod · 0.80
set_fileMethod · 0.80
startswithMethod · 0.45
joinMethod · 0.45

Tested by

no test coverage detected