From 7071168fdbe73b247d9e14d6a414c813e7e7b763 Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Mon, 16 Jan 2023 13:23:26 +0100 Subject: [PATCH 1/2] relax mypy in prototype namespace --- mypy.ini | 4 +--- torchvision/prototype/datapoints/_datapoint.py | 2 +- torchvision/prototype/transforms/_type_conversion.py | 2 +- torchvision/prototype/transforms/functional/_color.py | 2 +- torchvision/prototype/transforms/functional/_meta.py | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/mypy.ini b/mypy.ini index c1d174f4595..52243641731 100644 --- a/mypy.ini +++ b/mypy.ini @@ -7,7 +7,7 @@ allow_redefinition = True no_implicit_optional = True warn_redundant_casts = True -[mypy-torchvision.prototype.features.*] +[mypy-torchvision.prototype.datapoints.*] ; untyped definitions and calls disallow_untyped_defs = True @@ -17,7 +17,6 @@ no_implicit_optional = True ; warnings warn_unused_ignores = True -warn_return_any = True ; miscellaneous strictness flags allow_redefinition = True @@ -32,7 +31,6 @@ no_implicit_optional = True ; warnings warn_unused_ignores = True -warn_return_any = True ; miscellaneous strictness flags allow_redefinition = True diff --git a/torchvision/prototype/datapoints/_datapoint.py b/torchvision/prototype/datapoints/_datapoint.py index 659d4e958cc..d6472301e99 100644 --- a/torchvision/prototype/datapoints/_datapoint.py +++ b/torchvision/prototype/datapoints/_datapoint.py @@ -98,7 +98,7 @@ def __torch_function__( # `args = (torch.Tensor(), datapoints.Image())` first. Without this guard, the original `torch.Tensor` would # be wrapped into a `datapoints.Image`. if wrapper and isinstance(args[0], cls): - return wrapper(cls, args[0], output) # type: ignore[no-any-return] + return wrapper(cls, args[0], output) # Inplace `func`'s, canonically identified with a trailing underscore in their name like `.add_(...)`, # will retain the input type. Thus, we need to unwrap here. diff --git a/torchvision/prototype/transforms/_type_conversion.py b/torchvision/prototype/transforms/_type_conversion.py index 01908650fb4..c84aee62afe 100644 --- a/torchvision/prototype/transforms/_type_conversion.py +++ b/torchvision/prototype/transforms/_type_conversion.py @@ -46,7 +46,7 @@ class ToImageTensor(Transform): def _transform( self, inpt: Union[torch.Tensor, PIL.Image.Image, np.ndarray], params: Dict[str, Any] ) -> datapoints.Image: - return F.to_image_tensor(inpt) # type: ignore[no-any-return] + return F.to_image_tensor(inpt) class ToImagePIL(Transform): diff --git a/torchvision/prototype/transforms/functional/_color.py b/torchvision/prototype/transforms/functional/_color.py index 037bb5f8413..43ef49f0962 100644 --- a/torchvision/prototype/transforms/functional/_color.py +++ b/torchvision/prototype/transforms/functional/_color.py @@ -610,7 +610,7 @@ def equalize(inpt: datapoints.InputTypeJIT) -> datapoints.InputTypeJIT: def invert_image_tensor(image: torch.Tensor) -> torch.Tensor: if image.is_floating_point(): - return 1.0 - image # type: ignore[no-any-return] + return 1.0 - image elif image.dtype == torch.uint8: return image.bitwise_not() else: # signed integer dtypes diff --git a/torchvision/prototype/transforms/functional/_meta.py b/torchvision/prototype/transforms/functional/_meta.py index 28de0536978..27c02d04801 100644 --- a/torchvision/prototype/transforms/functional/_meta.py +++ b/torchvision/prototype/transforms/functional/_meta.py @@ -127,7 +127,7 @@ def get_spatial_size(inpt: datapoints.InputTypeJIT) -> List[int]: elif isinstance(inpt, (datapoints.Image, datapoints.Video, datapoints.BoundingBox, datapoints.Mask)): return list(inpt.spatial_size) elif isinstance(inpt, PIL.Image.Image): - return get_spatial_size_image_pil(inpt) # type: ignore[no-any-return] + return get_spatial_size_image_pil(inpt) else: raise TypeError( f"Input can either be a plain tensor, any TorchVision datapoint, or a PIL image, " From 469874dfb530aca8fac952bcc08fa8254c454e30 Mon Sep 17 00:00:00 2001 From: Philip Meier Date: Mon, 16 Jan 2023 13:44:37 +0100 Subject: [PATCH 2/2] cleanup --- mypy.ini | 2 -- 1 file changed, 2 deletions(-) diff --git a/mypy.ini b/mypy.ini index 52243641731..900c5479c23 100644 --- a/mypy.ini +++ b/mypy.ini @@ -45,8 +45,6 @@ no_implicit_optional = True ; warnings warn_unused_ignores = True -warn_return_any = True -warn_unreachable = True ; miscellaneous strictness flags allow_redefinition = True