Skip to content

Commit

Permalink
refactor: use explicit exception chaining
Browse files Browse the repository at this point in the history
Satisfy the new B904 rule (PyCQA/flake8-bugbear#181) from `flake8-bugbear`
by using explicit exception chaining whenever an exception is being transformed.
  • Loading branch information
jkglasbrenner committed Sep 28, 2021
1 parent 1747fa0 commit 29ee504
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
Expand Up @@ -62,13 +62,13 @@ def _(estimator: Model, x: Any, pred_type: str, **kwargs) -> np.ndarray:
**kwargs,
)

except EstimatorPredictGenericPredTypeError:
except EstimatorPredictGenericPredTypeError as exc:
LOGGER.exception(
"Unknown pred_type argument for estimator_predict function.",
estimator="tensorflow.keras.Model",
pred_type=pred_type,
)
raise EstimatorPredictGenericPredTypeError
raise exc

return prediction

Expand Down
8 changes: 4 additions & 4 deletions src/mitre/securingai/pyplugs/_plugins.py
Expand Up @@ -223,22 +223,22 @@ def info(package: str, plugin: str, func: Optional[str] = None) -> PluginInfo:
try:
plugin_info = _PLUGINS[package][plugin]

except KeyError:
except KeyError as exc:
raise UnknownPluginError(
f"Could not find any plug-in named {plugin!r} inside {package!r}. "
"Use pyplugs.register to register functions as plug-ins"
)
) from exc

func = next(iter(plugin_info.keys())) if func is None else func

try:
return plugin_info[func]

except KeyError:
except KeyError as exc:
raise UnknownPluginFunctionError(
f"Could not find any function named {func!r} inside '{package}.{plugin}'. "
"Use pyplugs.register to register plug-in functions"
)
) from exc


@expose
Expand Down
4 changes: 2 additions & 2 deletions src/mitre/securingai/restapi/experiment/service.py
Expand Up @@ -90,8 +90,8 @@ def create_mlflow_experiment(self, experiment_name: str) -> int:
str
] = self._mlflow_tracking_service.create_experiment(experiment_name)

except RestException:
raise ExperimentMLFlowTrackingRegistrationError
except RestException as exc:
raise ExperimentMLFlowTrackingRegistrationError from exc

if experiment_id is None:
raise ExperimentMLFlowTrackingAlreadyExistsError
Expand Down
4 changes: 3 additions & 1 deletion src/mitre/securingai/sdk/cryptography/verify.py
Expand Up @@ -85,7 +85,9 @@ def verify_payload(payload: bytes, signature: bytes, public_key: RSAPublicKey) -
)

except InvalidSignature:
raise InvalidSignature("Payload and/or signature files failed verification")
raise InvalidSignature(
"Payload and/or signature files failed verification"
) from None

return True

Expand Down

0 comments on commit 29ee504

Please sign in to comment.