def make_type_info(name: str, is_abstract: bool = False, mro: List[TypeInfo] = None, bases: List[Instance] = None, typevars: List[str] = None) -> TypeInfo: """Make a TypeInfo suitable for use in unit tests.""" type_def = TypeDef(name, Block([]), None, []) type_def.fullname = name if typevars: v = [] # type: List[TypeVarDef] id = 1 for n in typevars: v.append(TypeVarDef(n, id, None)) id += 1 type_def.type_vars = v info = TypeInfo(SymbolTable(), type_def) if mro is None: mro = [] info.mro = [info] + mro if bases is None: if mro: # By default, assume that there is a single non-generic base. bases = [Instance(mro[0], [])] else: bases = [] info.bases = bases return info
self.m1i = make_type_info('M1', (INTERFACES, [self.gfi]), (BASE_DEFS, [Instance(self.gfi, [self.a])])) self.gfa = Instance(self.gfi, [self.a]) # GF<A> self.gfb = Instance(self.gfi, [self.b]) # GF<B> self.m1 = Instance(self.m1i, []) # M1 TypeInfo make_type_info(any name, any *args): """Make a TypeInfo suitable for use in unit tests.""" map = dict(args) type_def = TypeDef(name, Block([]), None, []) type_def.fullname = name if VARS in map: TypeVarDef[] v = [] id = 1 for n in map[VARS]: v.append(TypeVarDef(n, id)) id += 1 type_def.type_vars = TypeVars(v) info = TypeInfo(SymbolTable(), type_def) info.base = map.get(BASE, None) info.bases = map.get(BASE_DEFS, []) info.interfaces = map.get(INTERFACES, []) # TODO fix return info