<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def from_data(cls, type, **data):
 """Create an attachment from data. :param str type: attachment type :param kwargs data: additional attachment data :return: an attachment subclass object :rtype: `~groupy.api.attachments.Attachment` """

        try:
            return cls._types[type](**data)
        except KeyError:
            return cls(type=type, **data)
        except TypeError as e:
            error = 'could not create {!r} attachment'.format(type)
            raise TypeError('{}: {}'.format(error, e.args[0]))