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

Function transform_import_from

mypyc/irbuild/statement.py:450–469  ·  view source on GitHub ↗
(builder: IRBuilder, node: ImportFrom)

Source from the content-addressed store, hash-verified

448
449
450def transform_import_from(builder: IRBuilder, node: ImportFrom) -> None:
451 if node.is_mypy_only:
452 return
453
454 module_state = builder.graph[builder.module_name]
455 if builder.module_path.endswith("__init__.py"):
456 module_package = builder.module_name
457 elif module_state.ancestors is not None and module_state.ancestors:
458 module_package = module_state.ancestors[0]
459 else:
460 module_package = ""
461
462 id = importlib.util.resolve_name("." * node.relative + node.id, module_package)
463 builder.imports[id] = None
464
465 names = [name for name, _ in node.names]
466 as_names = [as_name or name for name, as_name in node.names]
467
468 parent_is_native = builder.is_native_module(id) and builder.is_same_group_module(id)
469 transform_import_from_buckets(builder, id, names, as_names, node.line, parent_is_native)
470
471
472# Import kind constants for classify_import_from.

Callers 1

visit_import_fromMethod · 0.90

Calls 5

resolve_nameMethod · 0.80
is_same_group_moduleMethod · 0.80
endswithMethod · 0.45
is_native_moduleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…