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

Code before:
        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)
            self._init_args.pop("self", None)  # removed to prevent recursion

        # 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)
                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

Review comment (suggestion):
We probably need to remove the following line above:

```python
self._init_args.pop("self", None)  # type: ignore[attr-defined]
```

Code after:
        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)
            self._init_args.pop("self", None)  # removed to prevent recursion

        # 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)
                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)