def set_attributes(self, doc, fields, parent_type=None):
self.raw_doc = doc<EOL>self.doc = doc_unwrap(doc)<EOL>self.fields = fields<EOL>self.parent_type = parent_type<EOL>self._raw_examples = OrderedDict()<EOL>self._examples = OrderedDict()<EOL>self._fields_by_name = {}  <EOL>for field in self.fields:<EOL><INDENT>if field.name in self._fields_by_name:<EOL><INDENT>orig_lineno = self._fields_by_name[field.name]._ast_node.lineno<EOL>raise InvalidSpec("<STR_LIT>" %<EOL>(field.name, orig_lineno),<EOL>field._ast_node.lineno)<EOL><DEDENT>self._fields_by_name[field.name] = field<EOL><DEDENT>cur_type = self.parent_type<EOL>while cur_type:<EOL><INDENT>for field in self.fields:<EOL><INDENT>if field.name in cur_type._fields_by_name:<EOL><INDENT>lineno = cur_type._fields_by_name[field.name]._ast_node.lineno<EOL>raise InvalidSpec(<EOL>"<STR_LIT>"<EOL>% (field.name, cur_type.name, lineno),<EOL>field._ast_node.lineno)<EOL><DEDENT><DEDENT>cur_type = cur_type.parent_type<EOL><DEDENT>for field in self.fields:<EOL><INDENT>for annotation in field.custom_annotations:<EOL><INDENT>if annotation.annotation_type.namespace.name != self.namespace.name:<EOL><INDENT>self.namespace.add_imported_namespace(<EOL>annotation.annotation_type.namespace,<EOL>imported_annotation_type=True)<EOL><DEDENT>if annotation.namespace.name != self.namespace.name:<EOL><INDENT>self.namespace.add_imported_namespace(<EOL>annotation.namespace,<EOL>imported_annotation=True)<EOL><DEDENT><DEDENT><DEDENT>self._is_forward_ref = False<EOL>
Fields are specified as a list so that order is preserved for display
purposes only. (Might be used for certain serialization formats...)

:param str doc: Description of type.
:param list(Field) fields: Ordered list of fields for type.
:param Optional[Composite] parent_type: The type this type inherits
    from.