From 7bc122916679b781be67b42d59873b828519f6e0 Mon Sep 17 00:00:00 2001 From: Nirav Sayanja <76609223+N-S8990@users.noreply.github.com> Date: Sat, 11 Jul 2026 17:51:48 +0530 Subject: [PATCH 1/2] feat: use Sequence instead of list in path type hints Change type annotations from list[PathLike] to Sequence_[PathLike] in from_csv, from_json, from_parquet, and from_text methods. This allows callers to pass tuples and other sequence types without type checker errors. Closes #5354 --- src/datasets/arrow_dataset.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/datasets/arrow_dataset.py b/src/datasets/arrow_dataset.py index 59451a640e6..195906e5529 100644 --- a/src/datasets/arrow_dataset.py +++ b/src/datasets/arrow_dataset.py @@ -1290,7 +1290,7 @@ def from_list( @staticmethod def from_csv( - path_or_paths: Union[PathLike, list[PathLike]], + path_or_paths: Union[PathLike, Sequence_[PathLike]], split: Optional[NamedSplit] = None, features: Optional[Features] = None, cache_dir: str = None, @@ -1430,7 +1430,7 @@ def from_generator( @staticmethod def from_json( - path_or_paths: Union[PathLike, list[PathLike]], + path_or_paths: Union[PathLike, Sequence_[PathLike]], split: Optional[NamedSplit] = None, features: Optional[Features] = None, cache_dir: str = None, @@ -1489,7 +1489,7 @@ def from_json( @staticmethod def from_parquet( - path_or_paths: Union[PathLike, list[PathLike]], + path_or_paths: Union[PathLike, Sequence_[PathLike]], split: Optional[NamedSplit] = None, features: Optional[Features] = None, cache_dir: str = None, @@ -1586,7 +1586,7 @@ def from_parquet( @staticmethod def from_text( - path_or_paths: Union[PathLike, list[PathLike]], + path_or_paths: Union[PathLike, Sequence_[PathLike]], split: Optional[NamedSplit] = None, features: Optional[Features] = None, cache_dir: str = None, From 70d703abd012e08303e1341205203916223a70c6 Mon Sep 17 00:00:00 2001 From: Nirav Sayanja <76609223+N-S8990@users.noreply.github.com> Date: Sat, 11 Jul 2026 19:16:50 +0530 Subject: [PATCH 2/2] feat: use ListLike instead of list in path type hints Change path_or_paths type annotation from list[PathLike] to ListLike[PathLike] in from_csv, from_json, from_parquet, and from_text. list is invariant, so passing a tuple of paths fails mypy despite working at runtime. ListLike (defined in utils/typing.py) accepts both list and tuple and is already used elsewhere in this file. Type-annotation-only change, no runtime behavior difference. Verified with full test suite (151 passed) and before/after mypy diff. Closes #5354 --- src/datasets/arrow_dataset.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/datasets/arrow_dataset.py b/src/datasets/arrow_dataset.py index 195906e5529..508488ea05e 100644 --- a/src/datasets/arrow_dataset.py +++ b/src/datasets/arrow_dataset.py @@ -1290,7 +1290,7 @@ def from_list( @staticmethod def from_csv( - path_or_paths: Union[PathLike, Sequence_[PathLike]], + path_or_paths: Union[PathLike, ListLike[PathLike]], split: Optional[NamedSplit] = None, features: Optional[Features] = None, cache_dir: str = None, @@ -1303,7 +1303,7 @@ def from_csv( Read the CSV files, cache the data in Arrow format on disk and return the Dataset from the memory-mapped Arrow data on disk. Args: - path_or_paths (`path-like` or list of `path-like`): + path_or_paths (`path-like` or `Sequence` of `path-like`): Path(s) of the CSV file(s). split ([`NamedSplit`], *optional*): Split name to be assigned to the dataset. @@ -1430,7 +1430,7 @@ def from_generator( @staticmethod def from_json( - path_or_paths: Union[PathLike, Sequence_[PathLike]], + path_or_paths: Union[PathLike, ListLike[PathLike]], split: Optional[NamedSplit] = None, features: Optional[Features] = None, cache_dir: str = None, @@ -1444,7 +1444,7 @@ def from_json( Read the JSON files, cache the data in Arrow format on disk and return the Dataset from the memory-mapped Arrow data on disk. Args: - path_or_paths (`path-like` or list of `path-like`): + path_or_paths (`path-like` or `Sequence` of `path-like`): Path(s) of the JSON or JSON Lines file(s). split ([`NamedSplit`], *optional*): Split name to be assigned to the dataset. @@ -1489,7 +1489,7 @@ def from_json( @staticmethod def from_parquet( - path_or_paths: Union[PathLike, Sequence_[PathLike]], + path_or_paths: Union[PathLike, ListLike[PathLike]], split: Optional[NamedSplit] = None, features: Optional[Features] = None, cache_dir: str = None, @@ -1506,7 +1506,7 @@ def from_parquet( Read the Parquet files, cache the data in Arrow format on disk and return the Dataset from the memory-mapped Arrow data on disk. Args: - path_or_paths (`path-like` or list of `path-like`): + path_or_paths (`path-like` or `Sequence` of `path-like`): Path(s) of the Parquet file(s). split (`NamedSplit`, *optional*): Split name to be assigned to the dataset. @@ -1586,7 +1586,7 @@ def from_parquet( @staticmethod def from_text( - path_or_paths: Union[PathLike, Sequence_[PathLike]], + path_or_paths: Union[PathLike, ListLike[PathLike]], split: Optional[NamedSplit] = None, features: Optional[Features] = None, cache_dir: str = None, @@ -1601,7 +1601,7 @@ def from_text( Read the text files, cache the data in Arrow format on disk and return the Dataset from the memory-mapped Arrow data on disk. Args: - path_or_paths (`path-like` or list of `path-like`): + path_or_paths (`path-like` or `Sequence` of `path-like`): Path(s) of the text file(s). split (`NamedSplit`, *optional*): Split name to be assigned to the dataset.