(
input_lines: list[str], compiler_options: CompilerOptions | None = None
)
| 98 | |
| 99 | |
| 100 | def 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 | |
| 146 | def update_testcase_output(testcase: DataDrivenTestCase, output: list[str]) -> None: |
no test coverage detected
searching dependent graphs…