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

Code before:
        def save(self: Self, data: _DI) -> None:
            if data is None:
                raise DatasetError("Saving 'None' to a 'Dataset' is not allowed")

            try:
                self._logger.debug("Saving %s", str(self))
                save_func(self, data)
            except (DatasetError, FileNotFoundError, NotADirectoryError):
                raise
            except Exception as exc:
                message = f"Failed while saving data to dataset {self!s}.\n{exc!s}"
                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:
        """Customizes the behavior of subclasses of AbstractDataset during
        their creation. This method is automatically invoked when a subclass
        of AbstractDataset is defined.

        Decorates the `load` and `save` methods provided by the class.
        If `_load` or `_save` are defined, alias them as a prerequisite.

        """

        # Save the original __init__ method of the subclass
        init_func: Callable = cls.__init__

        def new_init(self, *args, **kwargs) -> None:  # type: ignore[no-untyped-def]
            """Executes the original __init__, then save the arguments used
            to initialize the instance.
            """
            # Call the original __init__ method
            init_func(self, *args, **kwargs)
            # Capture and save the arguments passed to the original __init__
            call_args = getcallargs(init_func, self, *args, **kwargs)
            self._init_args = call_args

        # Replace the subclass's __init__ with the new_init
        # A hook for subclasses to capture initialization arguments and save them
        # in the AbstractDataset._init_args field
        cls.__init__ = new_init  # type: ignore[method-assign]

        super().__init_subclass__(**kwargs)

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


Review comment (suggestion):
```suggestion
        @wraps(init_func)
        def new_init(self, *args, **kwargs) -> None:  # type: ignore[no-untyped-def]
```

I think we need this in order to make sure that `cls.__init__.__name__` and `cls.__init__.__doc__` are correct even if we wrap it with `new_init`. For more information, see: https://docs.python.org/3/library/functools.html#functools.wraps

Code after:
                save_func(self, data)
            except (DatasetError, FileNotFoundError, NotADirectoryError):
                raise
            except Exception as exc:
                message = f"Failed while saving data to dataset {self!s}.\n{exc!s}"
                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:
        """Customizes the behavior of subclasses of AbstractDataset during
        their creation. This method is automatically invoked when a subclass
        of AbstractDataset is defined.

        Decorates the `load` and `save` methods provided by the class.
        If `_load` or `_save` are defined, alias them as a prerequisite.
        """

        # Save the original __init__ method of the subclass
        init_func: Callable = cls.__init__

        @wraps(init_func)
        def new_init(self, *args, **kwargs) -> None:  # type: ignore[no-untyped-def]
            """Executes the original __init__, then save the arguments used
            to initialize the instance.
            """
            # Call the original __init__ method
            init_func(self, *args, **kwargs)
            # Capture and save the arguments passed to the original __init__
            self._init_args = getcallargs(init_func, self, *args, **kwargs)

        # Replace the subclass's __init__ with the new_init
        # A hook for subclasses to capture initialization arguments and save them
        # in the AbstractDataset._init_args field
        cls.__init__ = new_init  # type: ignore[method-assign]

        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)