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

Code before:
            list(self._dataset_patterns.keys())
            + list(self._default_pattern.keys())
            + list(self._runtime_patterns.keys())
        )

    @classmethod
    def _get_matches(cls, pattens: Iterable[str], ds_name: str) -> Generator[str]:
        return (pattern for pattern in pattens if parse(pattern, ds_name))

    def match_pattern(self, ds_name: str) -> str | None:
        """Match a dataset name against catalog patterns in a dictionary."""
        matches = self._get_matches(self._dataset_patterns.keys(), ds_name)
        return next(matches, None)

    def match_default_pattern(self, ds_name: str) -> str:
        """Match a dataset name against default patterns in a dictionary."""
        default_patters = set(self._default_pattern.keys())
        default_patters.update(set(self._runtime_patterns.keys()))
        matches = self._get_matches(default_patters, ds_name)
        # We assume runtime pattern always matches at the end
        return next(matches)

    def _get_pattern_config(self, pattern: str) -> dict[str, Any]:
        return (
            self._dataset_patterns.get(pattern)
            or self._default_pattern.get(pattern)
            or self._runtime_patterns.get(pattern)
            or {}
        )

    @classmethod
    def _extract_patterns(
        cls,
        config: dict[str, dict[str, Any]] | None,
        credentials: dict[str, dict[str, Any]] | None,
    ) -> tuple[Patterns, Patterns]:
        """Extract and sort patterns from the configuration."""
        config = config or {}
        credentials = credentials or {}
        dataset_patterns = {}
        user_default = {}

        for ds_name, ds_config in config.items():
            if cls.is_pattern(ds_name):
                cls._validate_pattern_config(ds_name, ds_config)
                dataset_patterns[ds_name] = cls._resolve_credentials(
                    ds_config, credentials
                )

        sorted_patterns = cls._sort_patterns(dataset_patterns)
        if sorted_patterns:

Review comment (suggestion):
Hi @ElenaKhaustova , 

I see `_runtime_patterns` can be `{}`. I am not sure how can we assume runtime pattern will always match at the end. Also my understanding is we look for 3 different areas for patterns -

1. _dataset_patterns - defined in catalog yaml
2. _default_pattern - catch all pattern defined by user (if not defaults to {})
3. _runtime_patterns - during a kedro run via modification to catalog directly ? (Not sure if I understood this right) (defaults to {})

When `_default_pattern` and `_runtime_patterns` can be `{}` do we assume it to be a match ? Could you please explain. Thank you


Code after:
            config = config.format_map(resolved_vars.named)
        return config

    def list_patterns(self) -> list[str]:
        """List al patterns available in the catalog."""
        return (
            list(self._dataset_patterns.keys())
            + list(self._default_pattern.keys())
            + list(self._runtime_patterns.keys())
        )

    @classmethod
    def _get_matches(cls, pattens: Iterable[str], ds_name: str) -> Generator[str]:
        return (pattern for pattern in pattens if parse(pattern, ds_name))

    def match_pattern(self, ds_name: str) -> str | None:
        """Match a dataset name against catalog patterns in a dictionary."""
        matches = self._get_matches(self._dataset_patterns.keys(), ds_name)
        return next(matches, None)

    def match_default_pattern(self, ds_name: str) -> str:
        """Match a dataset name against default patterns in a dictionary."""
        default_patters = set(self._default_pattern.keys())
        default_patters.update(set(self._runtime_patterns.keys()))
        matches = self._get_matches(default_patters, ds_name)
        # We assume runtime pattern always matches at the end
        return next(matches)

    def _get_pattern_config(self, pattern: str) -> dict[str, Any]:
        return (
            self._dataset_patterns.get(pattern)
            or self._default_pattern.get(pattern)
            or self._runtime_patterns.get(pattern)
            or {}
        )

    @classmethod
    def _extract_patterns(
        cls,
        config: dict[str, dict[str, Any]] | None,
        credentials: dict[str, dict[str, Any]] | None,
    ) -> tuple[Patterns, Patterns]:
        """Extract and sort patterns from the configuration."""
        config = config or {}
        credentials = credentials or {}
        dataset_patterns = {}
        user_default = {}

        for ds_name, ds_config in config.items():
            if cls.is_pattern(ds_name):
                cls._validate_pattern_config(ds_name, ds_config)