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

Code before:
        dataset = self.get(ds_name)

        if dataset is None:
            error_msg = f"Dataset '{ds_name}' not found in the catalog"
            # Flag to turn on/off fuzzy-matching which can be time consuming and
            # slow down plugins like `kedro-viz`
            if suggest:
                matches = difflib.get_close_matches(ds_name, self._datasets.keys())
                if matches:
                    suggestions = ", ".join(matches)
                    error_msg += f" - did you mean one of these instead: {suggestions}"
            raise DatasetNotFoundError(error_msg)

        if version and isinstance(dataset, AbstractVersionedDataset):
            # we only want to return a similar-looking dataset,
            # not modify the one stored in the current catalog
            dataset = dataset._copy(_version=version)

        return dataset

    def _get_dataset(
        self, dataset_name: str, version: Version | None = None, suggest: bool = True
    ) -> AbstractDataset:
        # TODO: remove when removing old catalog
        return self.get_dataset(dataset_name, version, suggest)

    def add(
        self, ds_name: str, dataset: AbstractDataset, replace: bool = False
    ) -> 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 == "":
            self._logger.warning("The empty string will not match any datasets")
            return []

        return self.keys(regex_search)

    def _filter_keys(self, regex_search: str | None) -> List[str]:  # noqa: UP006

Review comment (suggestion):
Can (should?) we add a method to remove a dataset? Either ``pop()`` or ``del`` (I saw elsewhere you did not ant to maintain all dict like methods, but I think this may be useful). I think it could be useful when one copy a catalog, filter a pipeline and just want to get some datasets associated to the filtered pipeline.  

Code after:

        if dataset is None:
            error_msg = f"Dataset '{ds_name}' not found in the catalog"
            # Flag to turn on/off fuzzy-matching which can be time consuming and
            # slow down plugins like `kedro-viz`
            if suggest:
                matches = difflib.get_close_matches(ds_name, self._datasets.keys())
                if matches:
                    suggestions = ", ".join(matches)
                    error_msg += f" - did you mean one of these instead: {suggestions}"
            raise DatasetNotFoundError(error_msg)

        if version and isinstance(dataset, AbstractVersionedDataset):
            # we only want to return a similar-looking dataset,
            # not modify the one stored in the current catalog
            dataset = dataset._copy(_version=version)

        return dataset

    def _get_dataset(
        self, dataset_name: str, version: Version | None = None, suggest: bool = True
    ) -> AbstractDataset:
        # TODO: remove when removing old catalog
        return self.get_dataset(dataset_name, version, suggest)

    def add(
        self, ds_name: str, dataset: AbstractDataset, replace: bool = False
    ) -> 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 []