Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2939 fixes B904 error #2940

Merged
merged 1 commit into from
Sep 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion monai/_extensions/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def timeout(time, message):
except KeyboardInterrupt as e:
if timer is not None and timer.is_alive():
raise e # interrupt from user?
raise TimeoutError(message)
raise TimeoutError(message) from e
finally:
if timer is not None:
try:
Expand Down
2 changes: 1 addition & 1 deletion monai/data/grid_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ def __iter__(self):
try:
iter_end = len(self.dataset) # TODO: support iterable self.dataset
except TypeError:
raise NotImplementedError("image dataset must implement `len()`.")
raise NotImplementedError("image dataset must implement `len()`.") from None

if worker_info is not None:
# split workload
Expand Down
4 changes: 2 additions & 2 deletions monai/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ def list_data_collate(batch: Sequence):
+ "`DataLoader` with `collate_fn=pad_list_data_collate` might solve this problem (check its "
+ "documentation)."
)
raise RuntimeError(re_str)
raise RuntimeError(re_str) from re
except TypeError as re:
re_str = str(re)
if "numpy" in re_str and "Tensor" in re_str:
Expand All @@ -294,7 +294,7 @@ def list_data_collate(batch: Sequence):
+ "creating your `DataLoader` with `collate_fn=pad_list_data_collate` might solve this problem "
+ "(check its documentation)."
)
raise TypeError(re_str)
raise TypeError(re_str) from re


def decollate_batch(batch, detach: bool = True):
Expand Down
2 changes: 1 addition & 1 deletion monai/transforms/inverse_batch_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def __call__(self, data: Dict[str, Any]) -> Any:
re_str = str(re)
if "equal size" in re_str:
re_str += "\nMONAI hint: try creating `BatchInverseTransform` with `collate_fn=lambda x: x`."
raise RuntimeError(re_str)
raise RuntimeError(re_str) from re


class Decollated(MapTransform):
Expand Down
4 changes: 2 additions & 2 deletions monai/utils/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def resolve_name(name):
try:
mod = importlib.import_module(modname)
obj = getattr(mod, declname, None)
except ModuleNotFoundError:
raise ValueError(f"Module {modname!r} not found.")
except ModuleNotFoundError as not_found_err:
raise ValueError(f"Module {modname!r} not found.") from not_found_err

if obj is None:
raise ValueError(f"Module {modname!r} does not have member {declname!r}.")
Expand Down
2 changes: 1 addition & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_pretrained_networks(network, input_param, device):
try:
net = network(**input_param).to(device)
except (URLError, HTTPError, ContentTooShortError) as e:
raise unittest.SkipTest(e)
raise unittest.SkipTest(e) from e
return net


Expand Down