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

Code before:
    def _get_save_path(self) -> PurePosixPath:
        if not self._version:
            # When versioning is disabled, return original filepath
            return self._filepath

        save_version = self.resolve_save_version()
        versioned_path = self._get_versioned_path(save_version)  # type: ignore[arg-type]

        if self._exists_function(str(versioned_path)):
            raise DatasetError(
                f"Save path '{versioned_path}' for {self!s} must not exist if "
                f"versioning is enabled."
            )

        return versioned_path

    def _get_versioned_path(self, version: str) -> PurePosixPath:
        return self._filepath / version / self._filepath.name

    def list_versions(self, full_path: bool = True) -> list:
        version_paths = self._get_versions()

        if full_path:
            return version_paths

        return [path.split(os.sep)[-2] for path in version_paths]  # [-2] is version dir

    @classmethod
    def _save_wrapper(
        cls, save_func: Callable[[Self, _DI], None]
    ) -> Callable[[Self, _DI], None]:
        """Decorate `save_func` with logging and error handling code."""

        @wraps(save_func)
        def save(self: Self, data: _DI) -> None:
            self._version_cache.clear()
            save_version = (
                self.resolve_save_version()
            )  # Make sure last save version is set
            try:
                super()._save_wrapper(save_func)(self, data)
            except (FileNotFoundError, NotADirectoryError) as err:
                # FileNotFoundError raised in Win, NotADirectoryError raised in Unix
                _default_version = "YYYY-MM-DDThh.mm.ss.sssZ"
                raise DatasetError(
                    f"Cannot save versioned dataset '{self._filepath.name}' to "
                    f"'{self._filepath.parent.as_posix()}' because a file with the same "
                    f"name already exists in the directory. This is likely because "
                    f"versioning was enabled on a dataset already saved previously. Either "
                    f"remove '{self._filepath.name}' from the directory or manually "
                    f"convert it into a versioned dataset by placing it in a versioned "

Review comment (suggestion):
```suggestion
        rreturn [PurePath(path).parent.name for path in version_paths]
```

Code after:

    def resolve_save_version(self) -> str | None:
        """Compute the version the dataset should be saved with."""
        if not self._version:
            return None
        if self._version.save:
            return self._version.save  # type: ignore[no-any-return]
        return self._fetch_latest_save_version()

    def _get_save_path(self) -> PurePosixPath:
        if not self._version:
            # When versioning is disabled, return original filepath
            return self._filepath

        save_version = self.resolve_save_version()
        versioned_path = self._get_versioned_path(save_version)  # type: ignore[arg-type]

        if self._exists_function(str(versioned_path)):
            raise DatasetError(
                f"Save path '{versioned_path}' for {self!s} must not exist if "
                f"versioning is enabled."
            )

        return versioned_path

    def _get_versioned_path(self, version: str) -> PurePosixPath:
        return self._filepath / version / self._filepath.name

    def _get_version_from_path(self, path: str) -> str:
        """Extract version string from a versioned dataset path.

        Args:
            path: Full path to a versioned dataset file.

        Returns:
            Version string extracted from the path.
        """
        return PurePath(path).parent.name

    def list_versions(self, full_path: bool = True) -> list[str]:
        """List all available versions of this dataset.

        This method allows you to retrieve all existing versions of a versioned
        dataset. It's useful for tracking dataset history, auditing changes, or
        implementing custom version selection logic.

        Args:
            full_path: If True, returns the full path to each version.
                If False, returns only the version strings (timestamps).

        Returns: