From 33f3cbe4336055e34014cbf49570dc28c5189bda Mon Sep 17 00:00:00 2001 From: F-G Fernandez <26927750+frgfm@users.noreply.github.com> Date: Thu, 27 Oct 2022 10:56:06 +0200 Subject: [PATCH 1/2] style: Fixed typing of dataset __getitem__ --- torchvision/datasets/dtd.py | 4 ++-- torchvision/datasets/flowers102.py | 2 +- torchvision/datasets/food101.py | 2 +- torchvision/datasets/rendered_sst2.py | 2 +- torchvision/datasets/sun397.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/torchvision/datasets/dtd.py b/torchvision/datasets/dtd.py index 2d8314346b9..2b10efe94e2 100644 --- a/torchvision/datasets/dtd.py +++ b/torchvision/datasets/dtd.py @@ -1,6 +1,6 @@ import os import pathlib -from typing import Callable, Optional +from typing import Any, Callable, Optional, Tuple import PIL.Image @@ -76,7 +76,7 @@ def __init__( def __len__(self) -> int: return len(self._image_files) - def __getitem__(self, idx): + def __getitem__(self, idx: int) -> Tuple[Any, Any]: image_file, label = self._image_files[idx], self._labels[idx] image = PIL.Image.open(image_file).convert("RGB") diff --git a/torchvision/datasets/flowers102.py b/torchvision/datasets/flowers102.py index ad3a6dda0e8..fdaf2ddb4d1 100644 --- a/torchvision/datasets/flowers102.py +++ b/torchvision/datasets/flowers102.py @@ -76,7 +76,7 @@ def __init__( def __len__(self) -> int: return len(self._image_files) - def __getitem__(self, idx) -> Tuple[Any, Any]: + def __getitem__(self, idx: int) -> Tuple[Any, Any]: image_file, label = self._image_files[idx], self._labels[idx] image = PIL.Image.open(image_file).convert("RGB") diff --git a/torchvision/datasets/food101.py b/torchvision/datasets/food101.py index e7d1bd19447..d2557a82736 100644 --- a/torchvision/datasets/food101.py +++ b/torchvision/datasets/food101.py @@ -69,7 +69,7 @@ def __init__( def __len__(self) -> int: return len(self._image_files) - def __getitem__(self, idx) -> Tuple[Any, Any]: + def __getitem__(self, idx: int) -> Tuple[Any, Any]: image_file, label = self._image_files[idx], self._labels[idx] image = PIL.Image.open(image_file).convert("RGB") diff --git a/torchvision/datasets/rendered_sst2.py b/torchvision/datasets/rendered_sst2.py index 89adf8cf8d8..58ea2f9cfe9 100644 --- a/torchvision/datasets/rendered_sst2.py +++ b/torchvision/datasets/rendered_sst2.py @@ -59,7 +59,7 @@ def __init__( def __len__(self) -> int: return len(self._samples) - def __getitem__(self, idx) -> Tuple[Any, Any]: + def __getitem__(self, idx: int) -> Tuple[Any, Any]: image_file, label = self._samples[idx] image = PIL.Image.open(image_file).convert("RGB") diff --git a/torchvision/datasets/sun397.py b/torchvision/datasets/sun397.py index 05cb910dde8..0a1ffef9b98 100644 --- a/torchvision/datasets/sun397.py +++ b/torchvision/datasets/sun397.py @@ -55,7 +55,7 @@ def __init__( def __len__(self) -> int: return len(self._image_files) - def __getitem__(self, idx) -> Tuple[Any, Any]: + def __getitem__(self, idx: int) -> Tuple[Any, Any]: image_file, label = self._image_files[idx], self._labels[idx] image = PIL.Image.open(image_file).convert("RGB") From fbc4766de142b9cf913f5de0929d2c3215678c47 Mon Sep 17 00:00:00 2001 From: F-G Fernandez <26927750+frgfm@users.noreply.github.com> Date: Thu, 27 Oct 2022 11:06:40 +0200 Subject: [PATCH 2/2] style: Fixed last missing typing --- torchvision/datasets/fgvc_aircraft.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torchvision/datasets/fgvc_aircraft.py b/torchvision/datasets/fgvc_aircraft.py index 2e4993361ca..aa705b305d8 100644 --- a/torchvision/datasets/fgvc_aircraft.py +++ b/torchvision/datasets/fgvc_aircraft.py @@ -90,7 +90,7 @@ def __init__( def __len__(self) -> int: return len(self._image_files) - def __getitem__(self, idx) -> Tuple[Any, Any]: + def __getitem__(self, idx: int) -> Tuple[Any, Any]: image_file, label = self._image_files[idx], self._labels[idx] image = PIL.Image.open(image_file).convert("RGB")