Repository: huggingface/datasets
File: src/datasets/dataset_dict.py (Python)

Code before:
                dataset_infos: dict = json.load(f)
                dataset_infos.get(config_name, None) if dataset_infos else None
        else:
            dataset_card = None
            dataset_card_data = DatasetCardData()
            metadata_configs = MetadataConfigs()
        # create the metadata configs if it was uploaded with push_to_hub before metadata configs existed
        if not metadata_configs:
            _matched_paths = [
                p
                for p in repo_files
                if fnmatch(p, PUSH_TO_HUB_WITHOUT_METADATA_CONFIGS_SPLIT_PATTERN_SHARDED.replace("{split}", "*"))
            ]
            if len(_matched_paths) > 0:
                # it was uploaded with push_to_hub before metadata configs existed
                _resolved_splits = {
                    string_to_dict(
                        p, glob_pattern_to_regex(PUSH_TO_HUB_WITHOUT_METADATA_CONFIGS_SPLIT_PATTERN_SHARDED)
                    )["split"]
                    for p in _matched_paths
                }
                default_metadata_configs_to_dump = {
                    "data_files": [
                        {"split": _resolved_split, "pattern": f"data/{_resolved_split}-*"}
                        for _resolved_split in _resolved_splits
                    ]
                }
                MetadataConfigs({"default": default_metadata_configs_to_dump}).to_dataset_card_data(dataset_card_data)
        # push to the deprecated dataset_infos.json
        if config.DATASETDICT_INFOS_FILENAME in repo_files:
            with open(dataset_infos_path, encoding="utf-8") as f:
                dataset_infos: DatasetInfosDict = json.load(f)
            dataset_infos[config_name] = asdict(info_to_dump)
            buffer = BytesIO()
            buffer.write(json.dumps(dataset_infos, indent=4).encode("utf-8"))
            HfApi(endpoint=config.HF_ENDPOINT).upload_file(
                path_or_fileobj=buffer.getvalue(),
                path_in_repo=config.DATASETDICT_INFOS_FILENAME,
                repo_id=repo_id,
                token=token,
                repo_type="dataset",
                revision=branch,
            )
        # push to README
        DatasetInfosDict({config_name: info_to_dump}).to_dataset_card_data(dataset_card_data)
        MetadataConfigs({config_name: metadata_config_to_dump}).to_dataset_card_data(dataset_card_data)
        dataset_card = (
            DatasetCard(
                "---\n"
                + str(dataset_card_data)
                + "\n---\n"

Review comment (suggestion):
this code needs to be here, because in the previous location it would be run only if there is no README.md and if there is a json file. But it needs to run if there is a json file, no matter if there is a README.md or not

Code after:
                if fnmatch(p, PUSH_TO_HUB_WITHOUT_METADATA_CONFIGS_SPLIT_PATTERN_SHARDED.replace("{split}", "*"))
            ]
            if len(_matched_paths) > 0:
                # it was uploaded with push_to_hub before metadata configs existed
                _resolved_splits = {
                    string_to_dict(
                        p, glob_pattern_to_regex(PUSH_TO_HUB_WITHOUT_METADATA_CONFIGS_SPLIT_PATTERN_SHARDED)
                    )["split"]
                    for p in _matched_paths
                }
                default_metadata_configs_to_dump = {
                    "data_files": [
                        {"split": _resolved_split, "pattern": f"data/{_resolved_split}-*"}
                        for _resolved_split in _resolved_splits
                    ]
                }
                MetadataConfigs({"default": default_metadata_configs_to_dump}).to_dataset_card_data(dataset_card_data)
        # push to the deprecated dataset_infos.json
        if config.DATASETDICT_INFOS_FILENAME in repo_files:
            download_config = DownloadConfig()
            download_config.download_desc = "Downloading metadata"
            download_config.token = token
            dataset_infos_path = cached_path(
                hf_hub_url(repo_id, config.DATASETDICT_INFOS_FILENAME),
                download_config=download_config,
            )
            with open(dataset_infos_path, encoding="utf-8") as f:
                dataset_infos: dict = json.load(f)
            dataset_infos[config_name] = asdict(info_to_dump)
            buffer = BytesIO()
            buffer.write(json.dumps(dataset_infos, indent=4).encode("utf-8"))
            HfApi(endpoint=config.HF_ENDPOINT).upload_file(
                path_or_fileobj=buffer.getvalue(),
                path_in_repo=config.DATASETDICT_INFOS_FILENAME,
                repo_id=repo_id,
                token=token,
                repo_type="dataset",
                revision=branch,
            )
        # push to README
        DatasetInfosDict({config_name: info_to_dump}).to_dataset_card_data(dataset_card_data)
        MetadataConfigs({config_name: metadata_config_to_dump}).to_dataset_card_data(dataset_card_data)
        dataset_card = (
            DatasetCard(
                "---\n"
                + str(dataset_card_data)
                + "\n---\n"
                + f'# Dataset Card for "{repo_id.split("/")[-1]}"\n\n[More Information needed](https://github.com/huggingface/datasets/blob/main/CONTRIBUTING.md#how-to-contribute-to-the-dataset-cards)'
            )
            if dataset_card is None
            else dataset_card