-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Closed
Labels
high prioritymodule: typingRelated to mypy type annotationsRelated to mypy type annotationstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate moduleThis issue has been looked at a team member, and triaged and prioritized into an appropriate module
Description
🐛 Bug
In dataloader.py#60, DataLoader does not inherit typing.Generic, but in dataloader.pyi#15 type inferace of DataLoader inherits typing.Generic.
Dataset is also in same situation. See also dataset.py#L8, dataset.pyi#L6.
To Reproduce
>>> import torch
>>> from typing import List
>>> from torch.utils.data import Dataset, DataLoader
>>> class SomeDatasetClass(Dataset[List[torch.Tensor]]):
... ...
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptable>>> import torch
>>> from typing import List
>>> from torch.utils.data import Dataset, DataLoader
>>> class SomeDatasetClass(Dataset):
... ...
...
>>> def _create_dataloader(is_train: bool) -> DataLoader[List[torch.Tensor]]:
... ...
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'type' object is not subscriptableExpected behavior
DataLoader and Dataset should inherit typing.Generic, so above code should run without any exceptions.
>>> from typing import Generic, TypeVar
>>> T = TypeVar('T')
>>> class SomeGenericClass(Generic[T]):
... ...
...
>>> def create_some_generic_class() -> SomeGenericClass[bool]:
... ...
...
>>>Like above code snippet.
Environment
- PyTorch Version (e.g., 1.0): 1.5.0
- Python version: Python 3.7.5
Additional context
I think this issue is related to #31765
ssnl, Spenhouet and i-yamane
Metadata
Metadata
Assignees
Labels
high prioritymodule: typingRelated to mypy type annotationsRelated to mypy type annotationstriagedThis issue has been looked at a team member, and triaged and prioritized into an appropriate moduleThis issue has been looked at a team member, and triaged and prioritized into an appropriate module