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

Function build_ir_for_single_file2

mypyc/test/testutil.py:100–143  ·  view source on GitHub ↗
(
    input_lines: list[str], compiler_options: CompilerOptions | None = None
)

Source from the content-addressed store, hash-verified

98
99
100def build_ir_for_single_file2(
101 input_lines: list[str], compiler_options: CompilerOptions | None = None
102) -> tuple[ModuleIR, MypyFile, dict[Expression, Type], Mapper]:
103 program_text = "\n".join(input_lines)
104
105 # By default generate IR compatible with the earliest supported Python C API.
106 # If a test needs more recent API features, this should be overridden.
107 compiler_options = compiler_options or CompilerOptions(capi_version=(3, 10))
108 options = Options()
109 options.show_traceback = True
110 options.hide_error_codes = True
111 options.use_builtins_fixtures = True
112 options.strict_optional = True
113 options.python_version = compiler_options.python_version or (3, 10)
114 options.export_types = True
115 options.preserve_asts = True
116 options.allow_empty_bodies = True
117 options.strict_bytes = True
118 options.disable_bytearray_promotion = True
119 options.disable_memoryview_promotion = True
120 options.per_module_options["__main__"] = {"mypyc": True}
121
122 source = build.BuildSource("main", "__main__", program_text)
123 # Construct input as a single single.
124 # Parse and type check the input program.
125 result = build.build(sources=[source], options=options, alt_lib_path=test_temp_dir)
126 result.manager.metastore.close()
127 if result.errors:
128 raise CompileError(result.errors)
129
130 errors = Errors(options)
131 mapper = Mapper({"__main__": None})
132 modules = build_ir(
133 [result.files["__main__"]], result.graph, result.types, mapper, compiler_options, errors
134 )
135 if errors.num_errors:
136 raise CompileError(errors.new_messages())
137
138 module = list(modules.values())[0]
139 for fn in module.functions:
140 assert_func_ir_valid(fn)
141 tree = result.graph[module.fullname].tree
142 assert tree is not None
143 return module, tree, result.types, mapper
144
145
146def update_testcase_output(testcase: DataDrivenTestCase, output: list[str]) -> None:

Callers 4

run_caseMethod · 0.90
run_caseMethod · 0.90
run_caseMethod · 0.90
build_ir_for_single_fileFunction · 0.85

Calls 13

new_messagesMethod · 0.95
CompilerOptionsClass · 0.90
OptionsClass · 0.90
CompileErrorClass · 0.90
ErrorsClass · 0.90
MapperClass · 0.90
build_irFunction · 0.90
assert_func_ir_validFunction · 0.90
listClass · 0.85
valuesMethod · 0.80
joinMethod · 0.45
buildMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…