Repository: apify/crawlee-python
File: src/crawlee/storage_clients/_file_system/_dataset_client.py (Python)

Code before:
        id: str | None,
        name: str | None,
        alias: str | None,
        configuration: Configuration,
    ) -> FileSystemDatasetClient:
        """Open or create a file system dataset client.

        This method attempts to open an existing dataset from the file system. If a dataset with the specified ID
        or name exists, it loads the metadata from the stored files. If no existing dataset is found, a new one
        is created.

        Args:
            id: The ID of the dataset to open. If provided, searches for existing dataset by ID.
            name: The name of the dataset for named (global scope) storages.
            alias: The alias of the dataset for unnamed (run scope) storages.
            configuration: The configuration object containing storage directory settings.

        Returns:
            An instance for the opened or created storage client.

        Raises:
            ValueError: If a dataset with the specified ID is not found, if metadata is invalid,
                or if both name and alias are provided.
        """
        # Validate input parameters.
        limit_kwarg_count(alias=alias, name=name, id=id)

        dataset_base_path = Path(configuration.storage_dir) / cls._STORAGE_SUBDIR

        if not dataset_base_path.exists():
            await asyncio.to_thread(dataset_base_path.mkdir, parents=True, exist_ok=True)

        # Get a new instance by ID.
        if id:
            found = False
            for dataset_dir in dataset_base_path.iterdir():
                if not dataset_dir.is_dir():
                    continue

                path_to_metadata = dataset_dir / METADATA_FILENAME
                if not path_to_metadata.exists():
                    continue

                try:
                    file = await asyncio.to_thread(path_to_metadata.open)
                    try:
                        file_content = json.load(file)
                        metadata = DatasetMetadata(**file_content)
                        if metadata.id == id:
                            client = cls(
                                metadata=metadata,

Review comment (suggestion):
I'm not sure about the name, `limit_kwarg_count` doesn't really suggest that this line will throw if there's more than one non-None value passed to the function. Also having to repeat each kwarg twice is pretty unwieldy.

Code after:
        id: str | None,
        name: str | None,
        alias: str | None,
        configuration: Configuration,
    ) -> FileSystemDatasetClient:
        """Open or create a file system dataset client.

        This method attempts to open an existing dataset from the file system. If a dataset with the specified ID
        or name exists, it loads the metadata from the stored files. If no existing dataset is found, a new one
        is created.

        Args:
            id: The ID of the dataset to open. If provided, searches for existing dataset by ID.
            name: The name of the dataset for named (global scope) storages.
            alias: The alias of the dataset for unnamed (run scope) storages.
            configuration: The configuration object containing storage directory settings.

        Returns:
            An instance for the opened or created storage client.

        Raises:
            ValueError: If a dataset with the specified ID is not found, if metadata is invalid,
                or if both name and alias are provided.
        """
        # Validate input parameters.
        raise_if_too_many_kwargs(id=id, name=name, alias=alias)

        dataset_base_path = Path(configuration.storage_dir) / cls._STORAGE_SUBDIR

        if not dataset_base_path.exists():
            await asyncio.to_thread(dataset_base_path.mkdir, parents=True, exist_ok=True)

        # Get a new instance by ID.
        if id:
            found = False
            for dataset_dir in dataset_base_path.iterdir():
                if not dataset_dir.is_dir():
                    continue

                path_to_metadata = dataset_dir / METADATA_FILENAME
                if not path_to_metadata.exists():
                    continue

                try:
                    file = await asyncio.to_thread(path_to_metadata.open)
                    try:
                        file_content = json.load(file)
                        metadata = DatasetMetadata(**file_content)
                        if metadata.id == id:
                            client = cls(
                                metadata=metadata,