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

Code before:
        by_type_set = set()
        if by_type:
            if not isinstance(by_type, list):
                by_type = [by_type]
            for _type in by_type:
                by_type_set.add(f"{_type.__module__}.{_type.__qualname__}")

        if by_type_set or type_regex:
            filtered_types = []
            for ds_name in filtered:
                # Retrieve the dataset type
                str_type = self.get_type(ds_name)
                # Match against type_regex and apply by_type filtering
                if (not type_regex or re.search(type_regex, str_type)) and (
                    not by_type_set or str_type in by_type_set
                ):
                    filtered_types.append(ds_name)

            return filtered_types

        return filtered

    def get_type(self, ds_name: str) -> str:
        """Access dataset type without adding resolved dataset to the catalog."""
        if ds_name not in self:
            return ""

        if ds_name not in self._datasets and ds_name not in self._lazy_datasets:
            ds_config = self._config_resolver.resolve_pattern(ds_name)
            return str(_LazyDataset(ds_name, ds_config))

        if ds_name in self._lazy_datasets:
            return str(self._lazy_datasets[ds_name])

        class_type = type(self._datasets[ds_name])
        return f"{class_type.__module__}.{class_type.__qualname__}"

    def save(self, ds_name: str, data: Any) -> None:
        """Save data to a registered dataset.

        Args:
            ds_name: The name of the dataset to be saved.
            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:
        ::

Review comment (bug):
Maybe this is something we should validate with users, IMO it also makes sense to return an error here saying the dataset doesn't exist/not found in the catalog. 

Code after:
        by_type_set = set()
        if by_type:
            if not isinstance(by_type, list):
                by_type = [by_type]
            for _type in by_type:
                by_type_set.add(f"{_type.__module__}.{_type.__qualname__}")

        if by_type_set or type_regex:
            filtered_types = []
            for ds_name in filtered:
                # Retrieve the dataset type
                str_type = self.get_type(ds_name)
                # Match against type_regex and apply by_type filtering
                if (not type_regex or re.search(type_regex, str_type)) and (
                    not by_type_set or str_type in by_type_set
                ):
                    filtered_types.append(ds_name)

            return filtered_types

        return filtered

    def get_type(self, ds_name: str) -> str:
        """Access dataset type without adding resolved dataset to the catalog.

        Raises:
            DatasetNotFoundError: When the dataset in not in the internal collection, does not match
                dataset_patterns or user_catch_all_pattern.
        """
        if ds_name not in self:
            raise DatasetNotFoundError(f"Dataset '{ds_name}' not found in the catalog")

        if ds_name not in self._datasets and ds_name not in self._lazy_datasets:
            ds_config = self._config_resolver.resolve_pattern(ds_name)
            return str(_LazyDataset(ds_name, ds_config))

        if ds_name in self._lazy_datasets:
            return str(self._lazy_datasets[ds_name])

        class_type = type(self._datasets[ds_name])
        return f"{class_type.__module__}.{class_type.__qualname__}"

    def save(self, ds_name: str, data: Any) -> None:
        """Save data to a registered dataset.

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

        Raises: