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

Function transform_non_native_import_group

mypyc/irbuild/statement.py:414–447  ·  view source on GitHub ↗

Transform a group of import statements that target non-native modules.

(
    builder: IRBuilder, group: list[tuple[str, str | None, int]]
)

Source from the content-addressed store, hash-verified

412
413
414def transform_non_native_import_group(
415 builder: IRBuilder, group: list[tuple[str, str | None, int]]
416) -> None:
417 """Transform a group of import statements that target non-native modules."""
418 modules = []
419 static_ptrs = []
420 # To show the right line number on failure, we have to add the traceback
421 # entry within the helper function (which is admittedly ugly). To drive
422 # this, we need the line number corresponding to each module.
423 mod_lines = []
424 first_line = group[0][2] if group else NO_TRACEBACK_LINE_NO
425 for mod_id, as_name, line in group:
426 builder.imports[mod_id] = None
427 modules.append((mod_id, *import_globals_id_and_name(mod_id, as_name)))
428 mod_static = LoadStatic(object_rprimitive, mod_id, namespace=NAMESPACE_MODULE)
429 static_ptrs.append(builder.add(LoadAddress(object_pointer_rprimitive, mod_static)))
430 mod_lines.append(Integer(line, c_pyssize_t_rprimitive))
431
432 static_array_ptr = builder.builder.setup_rarray(
433 object_pointer_rprimitive, static_ptrs, first_line
434 )
435 import_line_ptr = builder.builder.setup_rarray(c_pyssize_t_rprimitive, mod_lines, first_line)
436 builder.call_c(
437 import_many_op,
438 [
439 builder.add(LoadLiteral(tuple(modules), object_rprimitive)),
440 static_array_ptr,
441 builder.load_globals_dict(),
442 builder.load_str(builder.module_path),
443 builder.load_str(builder.fn_info.name),
444 import_line_ptr,
445 ],
446 NO_TRACEBACK_LINE_NO,
447 )
448
449
450def transform_import_from(builder: IRBuilder, node: ImportFrom) -> None:

Callers 1

transform_importFunction · 0.85

Calls 12

LoadStaticClass · 0.90
LoadAddressClass · 0.90
IntegerClass · 0.90
LoadLiteralClass · 0.90
tupleClass · 0.85
appendMethod · 0.80
setup_rarrayMethod · 0.80
load_globals_dictMethod · 0.80
addMethod · 0.45
call_cMethod · 0.45
load_strMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…