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

Code before:
                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:
        object_description = self._describe()
        if not isinstance(object_description, dict) or not all(
            isinstance(key, str) for key in object_description.keys()
        ):
            self._logger.warning(
                f"'{type(self).__module__}.{type(self).__name__}' is a subclass of AbstractDataset and it must "
                f"implement the '_describe' method following the signature of AbstractDataset's '_describe'."
            )
            return f"{type(self).__module__}.{type(self).__name__}()"
        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(

Review comment (suggestion):
- In 278 we already know that `object_description` is a `dict` because if it is not, the `or` expression would stop at 277 as return `True` from the left side of `or`.
- Therefore `.keys()` is redundant since default `for` over a `dict` is an iteration over its `keys` implicitly.

```suggestion
            isinstance(key, str) for key in object_description
```

Code after:
                    f"Failed while saving data to data set {str(self)}.\n{str(exc)}"
                )
                raise DatasetError(message) from exc

        save.__annotations__["data"] = save_func.__annotations__.get("data", Any)
        save.__annotations__["return"] = save_func.__annotations__.get("return")
        save.__savewrapped__ = True  # type: ignore[attr-defined]
        return save

    def __init_subclass__(cls, **kwargs: Any) -> None:
        """Decorate the `load` and `save` methods provided by the class.

        If `_load` or `_save` are defined, alias them as a prerequisite.

        """
        super().__init_subclass__(**kwargs)

        if hasattr(cls, "_load") and not cls._load.__qualname__.startswith("Abstract"):
            cls.load = cls._load  # type: ignore[method-assign]

        if hasattr(cls, "_save") and not cls._save.__qualname__.startswith("Abstract"):
            cls.save = cls._save  # type: ignore[method-assign]

        if hasattr(cls, "load") and not cls.load.__qualname__.startswith("Abstract"):
            cls.load = cls._load_wrapper(  # type: ignore[assignment]
                cls.load
                if not getattr(cls.load, "__loadwrapped__", False)
                else cls.load.__wrapped__  # type: ignore[attr-defined]
            )

        if hasattr(cls, "save") and not cls.save.__qualname__.startswith("Abstract"):
            cls.save = cls._save_wrapper(  # type: ignore[assignment]
                cls.save
                if not getattr(cls.save, "__savewrapped__", False)
                else cls.save.__wrapped__  # type: ignore[attr-defined]
            )

    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)})"