Repository: SuperDuperDB/superduperdb
File: superduperdb/components/datatype.py (Python)

Code before:
    @override
    def encode(self, leaf_types_to_keep: t.Sequence = ()):
        if self.x is not None and not isinstance(self.x, Empty):
            bytes_, sha1 = self._encode()
        else:
            bytes_, sha1 = None, None
        return {
            '_content': {
                'bytes': bytes_,
                'datatype': self.datatype.identifier,
                'leaf_type': self.leaf_type,
                'sha1': sha1,
                'uri': self.uri,
                'file_id': sha1 if self.file_id is None else self.file_id,
                'id': (
                    f'_{self.leaf_type}/'
                    f'{sha1 if self.file_id is None else self.file_id}',
                ),
            }
        }

    @classmethod
    def _get_object(cls, db, file_id, datatype, uri):
        obj = db.artifact_store.load_artifact(
            {
                'file_id': file_id,
                'datatype': datatype,
                'uri': uri,
            }
        )
        obj = db.datatypes[datatype].bytes_encoding_before_decode(obj)
        return obj

    def unpack(self, db):
        """
        Unpack the content of the `Encodable`

        :param db: `Datalayer` instance to assist with
        """
        self.init(db=db)
        return self.x

    def save(self, artifact_store):
        r = artifact_store.save_artifact(self.encode()['_content'])
        self.x = None
        self.file_id = r['file_id']

    @classmethod
    def decode(cls, r, db=None) -> 'Artifact':
        r = r['_content']
        x = cls._get_object(

Review comment (suggestion):
In the future, we can flexibly define the storage logic of artifacts according to the artifact_type (bytes, file, yaml, base64)

Code after:
            self.x = self._get_object(
                db,
                file_id=self.file_id,
                datatype=self.datatype.identifier,
                uri=self.uri,
            )

    @override
    def encode(self, leaf_types_to_keep: t.Sequence = ()):
        if self.x is not None and not isinstance(self.x, Empty):
            bytes_, sha1 = self._encode()
        else:
            bytes_, sha1 = None, None
        return {
            '_content': {
                'bytes': bytes_,
                'datatype': self.datatype.identifier,
                'leaf_type': self.leaf_type,
                'sha1': sha1,
                'uri': self.uri,
                'file_id': sha1 if self.file_id is None else self.file_id,
                'id': (
                    f'_{self.leaf_type}/'
                    f'{sha1 if self.file_id is None else self.file_id}',
                ),
                'artifact_type': 'bytes',
            }
        }

    @classmethod
    def _get_object(cls, db, file_id, datatype, uri):
        obj = db.artifact_store.load_artifact(
            {
                'file_id': file_id,
                'datatype': datatype,
                'uri': uri,
            }
        )
        obj = db.datatypes[datatype].bytes_encoding_before_decode(obj)
        return obj

    def unpack(self, db):
        """
        Unpack the content of the `Encodable`

        :param db: `Datalayer` instance to assist with
        """
        self.init(db=db)
        return self.x

    def save(self, artifact_store):