Repository: kedro-org/kedro
File: kedro/io/core.py (Python)

Code before:
            f"it must implement the '_load' method"
        )

    @abc.abstractmethod
    def _save(self, data: _DI) -> None:
        raise NotImplementedError(
            f"'{self.__class__.__name__}' is a subclass of AbstractDataset and "
            f"it must implement the '_save' method"
        )

    @abc.abstractmethod
    def _describe(self) -> dict[str, Any]:
        raise NotImplementedError(
            f"'{self.__class__.__name__}' is a subclass of AbstractDataset and "
            f"it must implement the '_describe' method"
        )

    def exists(self) -> bool:
        """Checks whether a data set's output already exists by calling
        the provided _exists() method.

        Returns:
            Flag indicating whether the output already exists.

        Raises:
            DatasetError: when underlying exists method raises error.

        """
        try:
            self._logger.debug("Checking whether target of %s exists", str(self))
            return self._exists()
        except Exception as exc:
            message = (
                f"Failed during exists check for data set {str(self)}.\n{str(exc)}"
            )
            raise DatasetError(message) from exc

    def _exists(self) -> bool:
        self._logger.warning(
            "'exists()' not implemented for '%s'. Assuming output does not exist.",
            self.__class__.__name__,
        )
        return False

    def release(self) -> None:
        """Release any cached data.

        Raises:
            DatasetError: when underlying release method raises error.

        """

Review comment (suggestion):
I think the issue with this is that all of the pretty-printed subkeys will be on a single line, and no formatting/wrapping is applied there. By using `PrettyPrinter` directly, you can get something pretty similar, and also get the formatting.

Happy to share some more context/pointers on this tomorrow or next week, if you'd like.

Code after:
                    fmt.format(key, _to_str(value))  # 2
                    for key, value in sorted_dict
                    if value is not None  # 3
                )

                return text if is_root else "{" + text + "}"  # 1

            # not a dictionary
            return str(obj)

        return f"{type(self).__name__}({_to_str(self._describe(), True)})"

    def _pretty_repr(self, object_description: dict[str, Any]) -> str:
        str_keys = []
        for arg_name, arg_descr in object_description.items():
            if arg_descr is not None:
                descr = pprint.pformat(
                    arg_descr,
                    sort_dicts=False,
                    compact=True,
                    depth=2,
                    width=sys.maxsize,
                )
                str_keys.append(f"{arg_name}={descr}")

        return f"{type(self).__module__}.{type(self).__name__}({', '.join(str_keys)})"

    def __repr__(self) -> str:
        return self._pretty_repr(self._describe())

    @abc.abstractmethod
    def _load(self) -> _DO:
        raise NotImplementedError(
            f"'{self.__class__.__name__}' is a subclass of AbstractDataset and "
            f"it must implement the '_load' method"
        )

    @abc.abstractmethod
    def _save(self, data: _DI) -> None:
        raise NotImplementedError(
            f"'{self.__class__.__name__}' is a subclass of AbstractDataset and "
            f"it must implement the '_save' method"
        )

    @abc.abstractmethod
    def _describe(self) -> dict[str, Any]:
        raise NotImplementedError(
            f"'{self.__class__.__name__}' is a subclass of AbstractDataset and "
            f"it must implement the '_describe' method"
        )