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

Code before:
            data_set = data_set._copy(  # pylint: disable=protected-access
                _version=version
            )

        return data_set

    def load(self, name: str, version: str = None) -> Any:
        """Loads a registered data set.

        Args:
            name: A data set to be loaded.
            version: Optional argument for concrete data version to be loaded.
                Works only with versioned datasets.

        Returns:
            The loaded data as configured.

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

        Example:
        ::

            >>> from kedro.io import DataCatalog
            >>> from kedro.extras.datasets.pandas import CSVDataSet
            >>>
            >>> cars = CSVDataSet(filepath="cars.csv",
            >>>                   load_args=None,
            >>>                   save_args={"index": False})
            >>> io = DataCatalog(data_sets={'cars': cars})
            >>>
            >>> df = io.load("cars")
        """
        load_version = Version(version, None) if version else None
        dataset = self._get_dataset(name, version=load_version)

        self._logger.info(
            "Loading data from '%s' (%s)...", name, type(dataset).__name__
        )

        result = dataset.load()

        return result

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

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

Review comment (suggestion):
This could be nicely rewritten to:
```
matches = (parse(pattern, data_set_name) for pattern in data_set_patterns.keys())
return next(filter(None, matches), None)
```

Code after:
                f"are not found in the catalog."
            )

        return cls(
            data_sets=data_sets,
            layers=dataset_layers,
            dataset_patterns=sorted_patterns,
            load_versions=load_versions,
            save_version=save_version,
        )

    @staticmethod
    def _is_pattern(pattern: str):
        """Check if a given string is a pattern. Assume that any name with '{' is a pattern."""
        return "{" in pattern

    @staticmethod
    def _match_pattern(
        data_set_patterns: dict[str, dict[str, Any]], data_set_name: str
    ) -> str | None:
        """Match a dataset name against patterns in a dictionary containing patterns"""
        for pattern, _ in data_set_patterns.items():
            result = parse(pattern, data_set_name)
            if result:
                return pattern
        return None

    @classmethod
    def _sort_patterns(
        cls, data_set_patterns: dict[str, dict[str, Any]]
    ) -> dict[str, dict[str, Any]]:
        """Sort a dictionary of dataset patterns according to parsing rules -
        1. Decreasing specificity (number of characters outside the curly brackets)
        2. Decreasing number of placeholders (number of curly bracket pairs)
        3. Alphabetically
        """
        sorted_keys = sorted(
            data_set_patterns,
            key=lambda pattern: (
                -(cls._specificity(pattern)),
                -pattern.count("{"),
                pattern,
            ),
        )
        sorted_patterns = {}
        for key in sorted_keys:
            sorted_patterns[key] = data_set_patterns[key]
        return sorted_patterns

    @staticmethod
    def _specificity(pattern: str) -> int: