Skip to content

Commit

Permalink
lint: try-except best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrugman committed Nov 24, 2021
1 parent 2732dd5 commit 4ee8c52
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Expand Up @@ -15,7 +15,8 @@ repos:
- id: flake8
additional_dependencies:
- flake8-comprehensions
args: [ "--select=E9,F63,F7,F82,C4,F401"]
- tryceratops
args: [ "--select=E9,F63,F7,F82,C4,F401,TR004,TC200,TC201,TC202"]
- repo: https://github.com/asottile/pyupgrade
rev: v2.29.1
hooks:
Expand Down
4 changes: 2 additions & 2 deletions popmon/analysis/profiling/hist_profiler.py
Expand Up @@ -162,8 +162,8 @@ def _profile_2d_histogram(self, name, hist):
return []
try:
grid = get_2dgrid(hist)
except Exception as e:
raise e
except Exception:
raise

# calc some basic 2d-histogram statistics
sume = int(sum_entries(hist))
Expand Down
4 changes: 2 additions & 2 deletions popmon/base/module.py
Expand Up @@ -140,8 +140,8 @@ def get_datastore_object(datastore, feature, dtype, default=None):
else:
try:
obj = datastore[feature]
except KeyError:
raise ValueError(f"`{feature}` not found in the datastore!")
except KeyError as e:
raise ValueError(f"`{feature}` not found in the datastore!") from e

if not isinstance(obj, dtype):
raise TypeError(f"obj `{feature}` is not an instance of `{dtype}`!")
Expand Down
8 changes: 5 additions & 3 deletions popmon/visualization/utils.py
Expand Up @@ -147,7 +147,7 @@ def plot_bars_b64(data, labels=None, bounds=None, ylim=False, skip_empty=True):
if y_max > y_min:
ax.set_ylim(y_min, y_max)
except Exception:
pass
logger.debug("unable to plot boundaries")

ax.grid(True, linestyle=":")

Expand Down Expand Up @@ -368,8 +368,10 @@ def plot_overlay_1d_histogram_b64(
try:
hist_values = hist[0]
hist_bins = hist[1]
except BaseException:
raise ValueError("Cannot extract binning and values from input histogram")
except BaseException as e:
raise ValueError(
"Cannot extract binning and values from input histogram"
) from e

assert hist_values is not None and len(
hist_values
Expand Down

0 comments on commit 4ee8c52

Please sign in to comment.