Skip to content

Commit

Permalink
lint fix: raise from None
Browse files Browse the repository at this point in the history
Summary: New linter warning is complaining about `raise` inside `except`.

Reviewed By: kjchalup

Differential Revision: D37819264

fbshipit-source-id: 56ad5d0558ea39e1125f3c76b43b7376aea2bc7c
  • Loading branch information
bottler authored and facebook-github-bot committed Jul 14, 2022
1 parent 8ba9a69 commit 8e0c82b
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions pytorch3d/datasets/r2n2/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pytorch3d/implicitron/models/global_encoder/autodecoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def forward(self, x: Union[torch.LongTensor, List[str]]) -> Optional[torch.Tenso
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)
Expand Down
2 changes: 1 addition & 1 deletion pytorch3d/implicitron/tools/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def update(self, preds, time_start=None, freeze_iter=False, stat_set="train"):
"could not extract prediction %s\
from the prediction dictionary"
% stat
)
) from None
else:
val = None

Expand Down
6 changes: 3 additions & 3 deletions pytorch3d/io/off_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pytorch3d/io/ply_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def _parse_element(self, line: str):
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))


Expand Down Expand Up @@ -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)
Expand All @@ -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)


Expand Down
2 changes: 1 addition & 1 deletion pytorch3d/ops/points_alignment.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 8e0c82b

Please sign in to comment.