def set(self, item: Union[Service, PublicKey]) -> 'DIDDoc':
        """
        Add or replace service or public key; return current DIDDoc.

        Raise BadDIDDocItem if input item is neither service nor public key.

        :param item: service or public key to set
        :return: current DIDDoc
        """

        if isinstance(item, Service):
            self.service[item.id] = item
        elif isinstance(item, PublicKey):
            self.pubkey[item.id] = item
        else:
            raise BadDIDDocItem('Cannot add item {} to DIDDoc on DID {}'.format(item, self.did))
Add or replace service or public key; return current DIDDoc.

        Raise BadDIDDocItem if input item is neither service nor public key.

        :param item: service or public key to set
        :return: current DIDDoc