From 8e0c82b89a96a1f1bed1ae5b84bd37524d0fe154 Mon Sep 17 00:00:00 2001 From: Jeremy Reizenstein Date: Thu, 14 Jul 2022 04:21:44 -0700 Subject: [PATCH] lint fix: raise from None Summary: New linter warning is complaining about `raise` inside `except`. Reviewed By: kjchalup Differential Revision: D37819264 fbshipit-source-id: 56ad5d0558ea39e1125f3c76b43b7376aea2bc7c --- pytorch3d/datasets/r2n2/utils.py | 4 ++-- .../implicitron/models/global_encoder/autodecoder.py | 2 +- pytorch3d/implicitron/tools/stats.py | 2 +- pytorch3d/io/off_io.py | 6 +++--- pytorch3d/io/ply_io.py | 8 ++++---- pytorch3d/ops/points_alignment.py | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pytorch3d/datasets/r2n2/utils.py b/pytorch3d/datasets/r2n2/utils.py index 6e9611ee..c7b80537 100644 --- a/pytorch3d/datasets/r2n2/utils.py +++ b/pytorch3d/datasets/r2n2/utils.py @@ -276,7 +276,7 @@ def _read_binvox_header(f): # pragma: no cover try: dims = [int(d) for d in dims[1:]] except ValueError: - raise ValueError("Invalid header (line 2)") + raise ValueError("Invalid header (line 2)") from None if len(dims) != 3 or dims[0] != dims[1] or dims[0] != dims[2]: raise ValueError("Invalid header (line 2)") size = dims[0] @@ -291,7 +291,7 @@ def _read_binvox_header(f): # pragma: no cover try: translation = tuple(float(t) for t in translation[1:]) except ValueError: - raise ValueError("Invalid header (line 3)") + raise ValueError("Invalid header (line 3)") from None # Fourth line of the header should be "scale [float]" line = f.readline().strip() diff --git a/pytorch3d/implicitron/models/global_encoder/autodecoder.py b/pytorch3d/implicitron/models/global_encoder/autodecoder.py index e93e15e4..5a072d54 100644 --- a/pytorch3d/implicitron/models/global_encoder/autodecoder.py +++ b/pytorch3d/implicitron/models/global_encoder/autodecoder.py @@ -107,7 +107,7 @@ class Autodecoder(Configurable, torch.nn.Module): device=next(self.parameters()).device, ) except StopIteration: - raise ValueError("Not enough n_instances in the autodecoder") + raise ValueError("Not enough n_instances in the autodecoder") from None # pyre-fixme[29]: `Union[torch.Tensor, torch.nn.Module]` is not a function. return self._autodecoder_codes(x) diff --git a/pytorch3d/implicitron/tools/stats.py b/pytorch3d/implicitron/tools/stats.py index 16eebe9f..4f01f55f 100644 --- a/pytorch3d/implicitron/tools/stats.py +++ b/pytorch3d/implicitron/tools/stats.py @@ -238,7 +238,7 @@ class Stats(object): "could not extract prediction %s\ from the prediction dictionary" % stat - ) + ) from None else: val = None diff --git a/pytorch3d/io/off_io.py b/pytorch3d/io/off_io.py index aa5e5d1b..4262269e 100644 --- a/pytorch3d/io/off_io.py +++ b/pytorch3d/io/off_io.py @@ -85,7 +85,7 @@ def _read_faces_lump( if n_faces > 1 and "Wrong number of columns" in e.args[0]: file.seek(old_offset) return None - raise ValueError("Not enough face data.") + raise ValueError("Not enough face data.") from None if len(data) != n_faces: raise ValueError("Not enough face data.") @@ -247,11 +247,11 @@ def _load_off_stream(file) -> dict: try: n_verts = int(items[0]) except ValueError: - raise ValueError("Invalid counts line: %s" % header) + raise ValueError("Invalid counts line: %s" % header) from None try: n_faces = int(items[1]) except ValueError: - raise ValueError("Invalid counts line: %s" % header) + raise ValueError("Invalid counts line: %s" % header) from None if (len(items) > 3 and not items[3].startswith(b"#")) or n_verts < 0 or n_faces < 0: raise ValueError("Invalid counts line: %s" % header) diff --git a/pytorch3d/io/ply_io.py b/pytorch3d/io/ply_io.py index 5ec7f662..d692b25b 100644 --- a/pytorch3d/io/ply_io.py +++ b/pytorch3d/io/ply_io.py @@ -236,7 +236,7 @@ class _PlyHeader: count = int(items[2]) except ValueError: msg = "Number of items for %s was not a number." - raise ValueError(msg % items[1]) + raise ValueError(msg % items[1]) from None self.elements.append(_PlyElementType(items[1], count)) @@ -409,12 +409,12 @@ def _parse_heterogeneous_property_ascii(datum, line_iter, property: _Property): else: datum.append(int(value)) except ValueError: - raise ValueError("Bad numerical data.") + raise ValueError("Bad numerical data.") from None else: try: length = int(value) except ValueError: - raise ValueError("A list length was not a number.") + raise ValueError("A list length was not a number.") from None list_value = np.zeros(length, dtype=_PLY_TYPES[property.data_type].np_type) for i in range(length): inner_value = next(line_iter, None) @@ -423,7 +423,7 @@ def _parse_heterogeneous_property_ascii(datum, line_iter, property: _Property): try: list_value[i] = float(inner_value) except ValueError: - raise ValueError("Bad numerical data.") + raise ValueError("Bad numerical data.") from None datum.append(list_value) diff --git a/pytorch3d/ops/points_alignment.py b/pytorch3d/ops/points_alignment.py index 61e2bbb8..1b22b3cc 100644 --- a/pytorch3d/ops/points_alignment.py +++ b/pytorch3d/ops/points_alignment.py @@ -141,7 +141,7 @@ def iterative_closest_point( "(minibatch, dim, dim), T is a batch of dim-dimensional " "translations of shape (minibatch, dim) and s is a batch " "of scalars of shape (minibatch,)." - ) + ) from None # apply the init transform to the input point cloud Xt = _apply_similarity_transform(Xt, R, T, s) else: