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

Method gen_import

mypyc/irbuild/builder.py:482–532  ·  view source on GitHub ↗
(self, module: str, line: int)

Source from the content-addressed store, hash-verified

480 self.builder.set_immortal_if_free_threaded(val, line)
481
482 def gen_import(self, module: str, line: int) -> None:
483 self.imports[module] = None
484
485 needs_import, out = BasicBlock(), BasicBlock()
486 self.check_if_module_loaded(module, line, needs_import, out)
487
488 self.activate_block(needs_import)
489 if self.is_native_module(module) and self.is_same_group_module(module):
490 # Use custom import machinery for native-to-native imports in the same group
491 init_only_func = self.add(
492 LoadGlobal(c_pointer_rprimitive, f"CPyInitOnly_{exported_name(module)}")
493 )
494 exec_func = self.add(
495 LoadGlobal(c_pointer_rprimitive, f"CPyExec_{exported_name(module)}")
496 )
497 module_static = self.add(
498 LoadAddress(
499 object_pointer_rprimitive,
500 f"{MODULE_PREFIX}{exported_name(module + '__internal')}",
501 )
502 )
503 group_name = self.mapper.group_map.get(self.module_name)
504 if group_name is not None:
505 shared_lib_mod_name = shared_lib_name(group_name)
506 mod_dict = self.call_c(get_module_dict_op, [], line)
507 shared_lib_obj = self.primitive_op(
508 dict_get_item_op, [mod_dict, self.load_str(shared_lib_mod_name, line)], line
509 )
510 shared_lib_file = self.py_get_attr(shared_lib_obj, "__file__", line)
511 else:
512 shared_lib_file = self.none_object(line)
513 ext_suffix = self.load_str(EXT_SUFFIX, line)
514 is_pkg = self.is_package_module(module)
515 value = self.call_c(
516 native_import_op,
517 [
518 self.load_str(module, line),
519 init_only_func,
520 exec_func,
521 module_static,
522 shared_lib_file,
523 ext_suffix,
524 Integer(1 if is_pkg else 0, c_pyssize_t_rprimitive),
525 ],
526 line,
527 )
528 else:
529 # Import using generic Python C API
530 value = self.call_c(import_op, [self.load_str(module, line)], line)
531 self.add(InitStatic(value, module, namespace=NAMESPACE_MODULE))
532 self.goto_and_activate(out)
533
534 def check_if_module_loaded(
535 self, id: str, line: int, needs_import: BasicBlock, out: BasicBlock

Callers 5

get_module_attrMethod · 0.95
transform_import_allFunction · 0.80
transform_mypy_fileFunction · 0.80

Calls 15

activate_blockMethod · 0.95
is_native_moduleMethod · 0.95
is_same_group_moduleMethod · 0.95
addMethod · 0.95
call_cMethod · 0.95
primitive_opMethod · 0.95
load_strMethod · 0.95
py_get_attrMethod · 0.95
none_objectMethod · 0.95
is_package_moduleMethod · 0.95
goto_and_activateMethod · 0.95

Tested by

no test coverage detected