Skip to content

Commit 8dfcff7

Browse files
authored
partially enable type checking for .models (#2668)
* partially enable mypy for .models * fix existing errors * ignore error instead of using Union
1 parent be0b6d9 commit 8dfcff7

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

mypy.ini

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,23 @@ files = torchvision
44
show_error_codes = True
55
pretty = True
66

7-
;[mypy-torchvision.datasets.*]
7+
[mypy-torchvision.io._video_opt.*]
88

9-
;ignore_errors = True
9+
ignore_errors = True
1010

11-
[mypy-torchvision.io._video_opt.*]
11+
[mypy-torchvision.io.*]
12+
13+
ignore_errors = True
14+
15+
[mypy-torchvision.models.detection.*]
16+
17+
ignore_errors = True
18+
19+
[mypy-torchvision.models.densenet.*]
1220

1321
ignore_errors = True
1422

15-
[mypy-torchvision.models.*]
23+
[mypy-torchvision.models.quantization.*]
1624

1725
ignore_errors = True
1826

torchvision/models/googlenet.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,11 @@ def _forward(self, x):
193193
return x, aux2, aux1
194194

195195
@torch.jit.unused
196-
def eager_outputs(self, x, aux2, aux1):
197-
# type: (Tensor, Optional[Tensor], Optional[Tensor]) -> GoogLeNetOutputs
196+
def eager_outputs(self, x: Tensor, aux2: Tensor, aux1: Optional[Tensor]) -> GoogLeNetOutputs:
198197
if self.training and self.aux_logits:
199198
return _GoogLeNetOutputs(x, aux2, aux1)
200199
else:
201-
return x
200+
return x # type: ignore[return-value]
202201

203202
def forward(self, x):
204203
# type: (Tensor) -> GoogLeNetOutputs

torchvision/models/inception.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,11 @@ def _forward(self, x):
188188
return x, aux
189189

190190
@torch.jit.unused
191-
def eager_outputs(self, x, aux):
192-
# type: (Tensor, Optional[Tensor]) -> InceptionOutputs
191+
def eager_outputs(self, x: torch.Tensor, aux: Optional[Tensor]) -> InceptionOutputs:
193192
if self.training and self.aux_logits:
194193
return InceptionOutputs(x, aux)
195194
else:
196-
return x
195+
return x # type: ignore[return-value]
197196

198197
def forward(self, x):
199198
x = self._transform_input(x)

0 commit comments

Comments
 (0)