def build_type_map(mapper: Mapper, modules: List[MypyFile], graph: Graph, types: Dict[Expression, Type], options: CompilerOptions, errors: Errors) -> None: # Collect all classes defined in everything we are compiling classes = [] for module in modules: module_classes = [ node for node in module.defs if isinstance(node, ClassDef) ] classes.extend([(module, cdef) for cdef in module_classes]) # Collect all class mappings so that we can bind arbitrary class name # references even if there are import cycles. for module, cdef in classes: class_ir = ClassIR(cdef.name, module.fullname, is_trait(cdef), is_abstract=cdef.info.is_abstract) class_ir.is_ext_class = is_extension_class(cdef) if class_ir.is_ext_class: class_ir.deletable = cdef.info.deletable_attributes[:] # If global optimizations are disabled, turn of tracking of class children if not options.global_opts: class_ir.children = None mapper.type_to_ir[cdef.info] = class_ir # Populate structural information in class IR for extension classes. for module, cdef in classes: with catch_errors(module.path, cdef.line): if mapper.type_to_ir[cdef.info].is_ext_class: prepare_class_def(module.path, module.fullname, cdef, errors, mapper) else: prepare_non_ext_class_def(module.path, module.fullname, cdef, errors, mapper) # Collect all the functions also. We collect from the symbol table # so that we can easily pick out the right copy of a function that # is conditionally defined. for module in modules: for func in get_module_func_defs(module): prepare_func_def(module.fullname, None, func, mapper)
def catch_errors(self, line: int) -> Any: return catch_errors(self.module_path, line)