MCPcopy Create free account
hub / github.com/python/mypy / correct_relative_import

Function correct_relative_import

mypy/util.py:359–371  ·  view source on GitHub ↗
(
    cur_mod_id: str, relative: int, target: str, is_cur_package_init_file: bool
)

Source from the content-addressed store, hash-verified

357
358
359def correct_relative_import(
360 cur_mod_id: str, relative: int, target: str, is_cur_package_init_file: bool
361) -> tuple[str, bool]:
362 if relative == 0:
363 return target, True
364 parts = cur_mod_id.split(".")
365 rel = relative
366 if is_cur_package_init_file:
367 rel -= 1
368 ok = len(parts) >= rel
369 if rel != 0:
370 cur_mod_id = ".".join(parts[:-rel])
371 return cur_mod_id + (("." + target) if target else ""), ok
372
373
374fields_cache: Final[dict[type[object], list[str]]] = {}

Callers 4

process_importMethod · 0.90
visit_import_fromMethod · 0.90
visit_import_allMethod · 0.90

Calls 3

lenFunction · 0.85
splitMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…