huggingface/datasets

Consider using "Sequence" instead of "List"

Open

#5.354 geöffnet am 12. Dez. 2022

Auf GitHub ansehen
 (18 Kommentare) (0 Reaktionen) (1 zugewiesene Person)Python (2.496 Forks)batch import
enhancementgood first issue

Repository-Metriken

Stars
 (18.313 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 25T 5h) (21 gemergte PRs in 30 T)

Beschreibung

Feature request

Hi, please consider using Sequence type annotation instead of List in function arguments such as in Dataset.from_parquet(). It leads to type checking errors, see below.

How to reproduce

list_of_filenames = ["foo.parquet", "bar.parquet"]
ds = Dataset.from_parquet(list_of_filenames)

Expected mypy output:

Success: no issues found

Actual mypy output:

test.py:19: error: Argument 1 to "from_parquet" of "Dataset" has incompatible type "List[str]"; expected "Union[Union[str, bytes, PathLike[Any]], List[Union[str, bytes, PathLike[Any]]]]"  [arg-type]
test.py:19: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
test.py:19: note: Consider using "Sequence" instead, which is covariant

Env: mypy 0.991, Python 3.10.0, datasets 2.7.1

Contributor Guide