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

Code before:
    ) -> None:
        # TODO: remove when removing old catalog
        """Adds a new ``AbstractDataset`` object to the ``KedroDataCatalog``."""
        if ds_name in self._datasets and not replace:
            raise DatasetAlreadyExistsError(
                f"Dataset '{ds_name}' has already been registered"
            )
        self.__setitem__(ds_name, dataset)

    def list(self, regex_search: str | None = None) -> List[str]:  # noqa: UP006
        # TODO: remove when removing old catalog
        """
        List of all dataset names registered in the catalog.
        This can be filtered by providing an optional regular expression
        which will only return matching keys.
        """
        if regex_search is None:
            return self.keys()

        if regex_search == "":
            self._logger.warning("The empty string will not match any datasets")
            return []

        return self.filter(regex_search)

    def filter(
        self, regex_search: str, regex_flags: int | re.RegexFlag = 0
    ) -> List[str]:  # noqa: UP006
        """
        Filter dataset names registered in the catalog.
        """
        if not regex_flags:
            regex_flags = re.IGNORECASE

        try:
            pattern = re.compile(regex_search, flags=regex_flags)
        except re.error as exc:
            raise SyntaxError(
                f"Invalid regular expression provided: '{regex_search}'"
            ) from exc
        return [ds_name for ds_name in self.__iter__() if pattern.search(ds_name)]

    def save(self, name: str, data: Any) -> None:
        # TODO: rename input argument when breaking change: name -> ds_name
        """Save data to a registered dataset.

        Args:
            name: A dataset to be saved to.
            data: A data object to be saved as configured in the registered
                dataset.


Review comment (suggestion):
While I am usually in favour of simpler names, here `filter` is a bit ambiguous, since it's unclear what we are filtering exactly. If we are to keep a separate method, I'd rather keep `list()` with the regex. 

Code after:
    ) -> None:
        # TODO: remove when removing old catalog
        """Adds a new ``AbstractDataset`` object to the ``KedroDataCatalog``."""
        if ds_name in self._datasets and not replace:
            raise DatasetAlreadyExistsError(
                f"Dataset '{ds_name}' has already been registered"
            )
        self.__setitem__(ds_name, dataset)

    def list(
        self, regex_search: str | None = None, regex_flags: int | re.RegexFlag = 0
    ) -> List[str]:  # noqa: UP006
        # TODO: rename depending on the solution for https://github.com/kedro-org/kedro/issues/3917
        """
        List of all dataset names registered in the catalog.
        This can be filtered by providing an optional regular expression
        which will only return matching keys.
        """
        if regex_search is None:
            return self.keys()

        if regex_search == "":
            self._logger.warning("The empty string will not match any datasets")
            return []

        if not regex_flags:
            regex_flags = re.IGNORECASE

        try:
            pattern = re.compile(regex_search, flags=regex_flags)
        except re.error as exc:
            raise SyntaxError(
                f"Invalid regular expression provided: '{regex_search}'"
            ) from exc
        return [ds_name for ds_name in self.__iter__() if pattern.search(ds_name)]

    def save(self, name: str, data: Any) -> None:
        # TODO: rename input argument when breaking change: name -> ds_name
        """Save data to a registered dataset.

        Args:
            name: A dataset to be saved to.
            data: A data object to be saved as configured in the registered
                dataset.

        Raises:
            DatasetNotFoundError: When a dataset with the given name
                has not yet been registered.

        Example:
        ::