def annotator(klazz): assert issubclass(klazz, Structural) klazz_factory, klazz_name, klazz_bindings, klazz_attributes = klazz.serialize_type() old_type_environment = TypeEnvironment.deserialize(klazz_bindings, {}) new_type_environment = TypeEnvironment(*types, **bound_types) return TypeFactory.new({}, 'Struct', klazz_name, new_type_environment.merge(old_type_environment).serialize(), klazz_attributes)
def create(type_dict, *type_parameters): """ StructFactory.create(*type_parameters) expects: class name, ((binding requirement1,), (binding requirement2, bound_to_scope), ...), ((attribute_name1, attribute_sig1 (serialized)), (attribute_name2, attribute_sig2 ...), ... (attribute_nameN, ...)) """ name, bindings, parameters = type_parameters for param in parameters: assert isinstance(param, tuple) typemap = dict((attr, TypeSignature.deserialize(param, type_dict)) for attr, param in parameters) bindings = TypeEnvironment.deserialize(bindings, type_dict) attributes = {'TYPEMAP': typemap, 'REQUIRES': bindings} return TypeMetaclass(str(name), (Structural,), attributes)