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

Code before:
        return sorted_patterns

    @staticmethod
    def _specificity(pattern: str) -> int:
        """Helper function to check the length of exactly matched characters not inside brackets
        Example -
        specificity("{namespace}.companies") = 10
        specificity("{namespace}.{dataset}") = 1
        specificity("france.companies") = 16
        """
        # Remove all the placeholders from the pattern and count the number of remaining chars
        result = re.sub(r"\{.*?\}", "", pattern)
        return len(result)

    def _get_dataset(
        self, data_set_name: str, version: Version = None, suggest: bool = True
    ) -> AbstractDataSet:
        matched_pattern = self._match_pattern(self._dataset_patterns, data_set_name)
        if data_set_name not in self._data_sets and matched_pattern:
            # If the dataset is a patterned dataset, materialise it and add it to
            # the catalog
            data_set_config = self._resolve_config(data_set_name, matched_pattern)
            ds_layer = data_set_config.pop("layer", None)
            if ds_layer:
                if not self.layers:
                    self.layers = {}
                self.layers.setdefault(ds_layer, set()).add(data_set_name)
            data_set = AbstractDataSet.from_config(
                data_set_name,
                data_set_config,
                self._load_versions.get(data_set_name),
                self._save_version,
            )
            self.add(data_set_name, data_set)
        if data_set_name not in self._data_sets:
            error_msg = f"Dataset '{data_set_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(
                    data_set_name, self._data_sets.keys()
                )
                if matches:
                    suggestions = ", ".join(matches)
                    error_msg += f" - did you mean one of these instead: {suggestions}"
            raise DatasetNotFoundError(error_msg)
        data_set = self._data_sets[data_set_name]
        if version and isinstance(data_set, AbstractVersionedDataSet):
            # we only want to return a similar-looking dataset,
            # not modify the one stored in the current catalog

Review comment (suggestion):
This can be simplified to: 
```
self.layers = self.layers or {}
```

Code after:
    @staticmethod
    def _specificity(pattern: str) -> int:
        """Helper function to check the length of exactly matched characters not inside brackets
        Example -
        specificity("{namespace}.companies") = 10
        specificity("{namespace}.{dataset}") = 1
        specificity("france.companies") = 16
        """
        # Remove all the placeholders from the pattern and count the number of remaining chars
        result = re.sub(r"\{.*?\}", "", pattern)
        return len(result)

    def _get_dataset(
        self, data_set_name: str, version: Version = None, suggest: bool = True
    ) -> AbstractDataSet:
        matched_pattern = self._match_pattern(self._dataset_patterns, data_set_name)
        if data_set_name not in self._data_sets and matched_pattern:
            # If the dataset is a patterned dataset, materialise it and add it to
            # the catalog
            data_set_config = self._resolve_config(data_set_name, matched_pattern)
            ds_layer = data_set_config.pop("layer", None)
            if ds_layer:
                self.layers = self.layers or {}
                self.layers.setdefault(ds_layer, set()).add(data_set_name)
            data_set = AbstractDataSet.from_config(
                data_set_name,
                data_set_config,
                self._load_versions.get(data_set_name),
                self._save_version,
            )
            if self._specificity(matched_pattern) == 0:
                self._logger.warning(
                    "Config from the dataset factory pattern '%s' in the catalog will be used to "
                    "override the default MemoryDataset creation for the dataset '%s'",
                    matched_pattern,
                    data_set_name,
                )

            self.add(data_set_name, data_set)
        if data_set_name not in self._data_sets:
            error_msg = f"Dataset '{data_set_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(
                    data_set_name, self._data_sets.keys()
                )
                if matches:
                    suggestions = ", ".join(matches)
                    error_msg += f" - did you mean one of these instead: {suggestions}"