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

Code before:
        return [dset_name for dset_name in self._datasets if pattern.search(dset_name)]

    def shallow_copy(
        self, extra_dataset_patterns: Patterns | None = None
    ) -> DataCatalog:
        """Returns a shallow copy of the current object.

        Returns:
            Copy of the current object.
        """
        if not self._default_pattern and extra_dataset_patterns:
            unsorted_dataset_patterns = {
                **self._dataset_patterns,
                **extra_dataset_patterns,
            }
            dataset_patterns = self._sort_patterns(unsorted_dataset_patterns)
        else:
            dataset_patterns = self._dataset_patterns
        return self.__class__(
            datasets=self._datasets,
            dataset_patterns=dataset_patterns,
            load_versions=self._load_versions,
            save_version=self._save_version,
            default_pattern=self._default_pattern,
        )

    def __eq__(self, other) -> bool:  # type: ignore[no-untyped-def]
        return (self._datasets, self._dataset_patterns) == (
            other._datasets,
            other._dataset_patterns,
        )

    def confirm(self, name: str) -> None:
        """Confirm a dataset by its name.

        Args:
            name: Name of the dataset.
        Raises:
            DatasetError: When the dataset does not have `confirm` method.

        """
        self._logger.info("Confirming dataset '%s'", name)
        dataset = self._get_dataset(name)

        if hasattr(dataset, "confirm"):
            dataset.confirm()
        else:
            raise DatasetError(f"Dataset '{name}' does not have 'confirm' method")


Review comment (suggestion):
```suggestion
        return cls(
```

Need to add @classmethod at the top as well.

How about using `cls` directly? It seems a bit weird to use `self.__class__` in this case. This is also how we define the factory method `from_config`.


https://github.com/kedro-org/kedro/blob/b6e585f80ace1896e6bd3c31d827a1991ed2c664/kedro/io/data_catalog.py#L327-L333

Code after:
        try:
            pattern = re.compile(regex_search, flags=re.IGNORECASE)

        except re.error as exc:
            raise SyntaxError(
                f"Invalid regular expression provided: '{regex_search}'"
            ) from exc
        return [dset_name for dset_name in self._datasets if pattern.search(dset_name)]

    def shallow_copy(
        self, extra_dataset_patterns: Patterns | None = None
    ) -> DataCatalog:
        """Returns a shallow copy of the current object.

        Returns:
            Copy of the current object.
        """
        if not self._default_pattern and extra_dataset_patterns:
            unsorted_dataset_patterns = {
                **self._dataset_patterns,
                **extra_dataset_patterns,
            }
            dataset_patterns = self._sort_patterns(unsorted_dataset_patterns)
        else:
            dataset_patterns = self._dataset_patterns
        return self.__class__(
            datasets=self._datasets,
            dataset_patterns=dataset_patterns,
            load_versions=self._load_versions,
            save_version=self._save_version,
            default_pattern=self._default_pattern,
        )

    def __eq__(self, other) -> bool:  # type: ignore[no-untyped-def]
        return (self._datasets, self._dataset_patterns) == (
            other._datasets,
            other._dataset_patterns,
        )

    def confirm(self, name: str) -> None:
        """Confirm a dataset by its name.

        Args:
            name: Name of the dataset.
        Raises:
            DatasetError: When the dataset does not have `confirm` method.

        """
        self._logger.info("Confirming dataset '%s'", name)
        dataset = self._get_dataset(name)