Skip to content

feat: use ListLike instead of list in path type hints#8322

Open
N-S8990 wants to merge 2 commits into
huggingface:mainfrom
N-S8990:fix/use-sequence-instead-of-list
Open

feat: use ListLike instead of list in path type hints#8322
N-S8990 wants to merge 2 commits into
huggingface:mainfrom
N-S8990:fix/use-sequence-instead-of-list

Conversation

@N-S8990

@N-S8990 N-S8990 commented Jul 11, 2026

Copy link
Copy Markdown

Description

Changed type annotations from list[PathLike] to ListLike[PathLike] in
from_csv, from_json, from_parquet, and from_text.

list type hints are invariant — passing a tuple of paths fails mypy even
though it works fine at runtime. ListLike (defined in
src/datasets/utils/typing.py) accepts both list and tuple, and is already
used elsewhere in this file (see _getitem), so this follows an existing
project convention rather than introducing a new type alias.

Changes

  • src/datasets/arrow_dataset.py: changed 4 parameter type hints
    (from_csv, from_json, from_parquet, from_text) and updated their
    docstrings to match (path-like or list of path-likepath-like or Sequence of path-like).

Verification

  • Type-annotation-only change — no runtime behavior difference.
    path_or_paths is passed through unchanged to the underlying
    *DatasetReader classes.
  • Ran the existing test suite: 151 passed, 0 failures related to this change
    (5 unrelated failures are pre-existing, caused by a missing
    pytest-datadir fixture in compression-writer tests).
  • Ran mypy before and after this change and diffed the output. Mypy still
    reports a type mismatch between these methods and the internal
    *DatasetReader constructors (CsvDatasetReader, JsonDatasetReader,
    ParquetDatasetReader, TextDatasetReader), which are typed to accept
    list | dict only. Confirmed via diff that this mismatch is pre-existing
    on main
    (it appeared even when using Sequence_[PathLike] before
    switching to ListLike) — it is out of scope for this PR and would need a
    separate fix to the io/*.py reader constructor signatures.

Related Issue

Closes #5354

AI Disclosure

AI-assisted (Hermes Agent) — reviewed and tested manually by the author.

N-S8990 added 2 commits July 11, 2026 17:51
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 huggingface#5354
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 huggingface#5354
@N-S8990 N-S8990 changed the title feat: use Sequence instead of list in path type hints feat: use ListLike instead of list in path type hints Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider using "Sequence" instead of "List"

1 participant