Repository: SuperDuperDB/superduperdb
File: superduperdb/base/document.py (Python)

Code before:
        from superduperdb.base.serializable import _replace_variables

        content = _replace_variables(
            self.content, db, **kwargs
        )  # replace variables with values
        return Document(content)

    def outputs(self, key: str, model: str, version: t.Optional[int] = None) -> t.Any:
        """
        Get document ouputs on ``key`` from ``model``

        :param key: Document key to get outputs from.
        :param model: Model name to get outputs from.
        """
        r = MongoStyleDict(self.unpack())
        if version is not None:
            document = r[f'{_OUTPUTS_KEY}.{key}.{model}.{version}']
        else:
            tmp = r[f'{_OUTPUTS_KEY}.{key}.{model}']
            version = max(list(tmp.keys()))
            return tmp[version]
        return document

    @staticmethod
    def decode(
        r: t.Dict, encoders: t.Dict, bytes_encoding: t.Optional[t.Any] = None
    ) -> t.Any:
        bytes_encoding = bytes_encoding or CFG.bytes_encoding

        if isinstance(r, Document):
            return Document(_decode(r, encoders, bytes_encoding))
        elif isinstance(r, dict):
            return _decode(r, encoders, bytes_encoding)
        raise NotImplementedError(f'type {type(r)} is not supported')

    def __repr__(self) -> str:
        return f'Document({repr(self.content)})'

    def __getitem__(self, item: str) -> ItemType:
        assert isinstance(self.content, dict)
        return self.content[item]

    def __setitem__(self, key: str, value: ItemType):
        assert isinstance(self.content, dict)
        self.content[key] = value

    def unpack(self) -> t.Any:
        """Returns the content, but with any encodables replacecs by their contents"""
        return _unpack(self.content)



Review comment (suggestion):
```python
from superduperdb.base.config import BytesEncoding

...

    def decode(
        r: t.Dict, encoders: t.Dict, bytes_encoding: t.Optional[BytesEncoding] = None
    ):
        ...
```


Code after:
    def set_variables(self, db, **kwargs) -> 'Document':
        from superduperdb.base.serializable import _replace_variables

        content = _replace_variables(
            self.content, db, **kwargs
        )  # replace variables with values
        return Document(content)

    def outputs(self, key: str, model: str, version: t.Optional[int] = None) -> t.Any:
        """
        Get document ouputs on ``key`` from ``model``

        :param key: Document key to get outputs from.
        :param model: Model name to get outputs from.
        """
        r = MongoStyleDict(self.unpack())
        if version is not None:
            document = r[f'{_OUTPUTS_KEY}.{key}.{model}.{version}']
        else:
            tmp = r[f'{_OUTPUTS_KEY}.{key}.{model}']
            version = max(list(tmp.keys()))
            return tmp[version]
        return document

    @staticmethod
    def decode(
        r: t.Dict, encoders: t.Dict, bytes_encoding: t.Optional[BytesEncoding] = None
    ) -> t.Any:
        bytes_encoding = bytes_encoding or CFG.bytes_encoding

        if isinstance(r, Document):
            return Document(_decode(r, encoders, bytes_encoding))
        elif isinstance(r, dict):
            return _decode(r, encoders, bytes_encoding)
        raise NotImplementedError(f'type {type(r)} is not supported')

    def __repr__(self) -> str:
        return f'Document({repr(self.content)})'

    def __getitem__(self, item: str) -> ItemType:
        assert isinstance(self.content, dict)
        return self.content[item]

    def __setitem__(self, key: str, value: ItemType):
        assert isinstance(self.content, dict)
        self.content[key] = value

    def unpack(self) -> t.Any:
        """Returns the content, but with any encodables replacecs by their contents"""
        return _unpack(self.content)