Skip to content

Commit

Permalink
avoid use of assert
Browse files Browse the repository at this point in the history
  • Loading branch information
wxtim committed Jan 31, 2024
1 parent ea50b53 commit b543af7
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions cylc/flow/xtriggers/xrandom.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,32 @@ def validate(f_args, f_kwargs, f_signature):
f_kwargs["percent"] = f_args[0]
del f_args[0]

should_raise = False

try:
percent = f_kwargs['percent']
percent = float(percent)
assert isinstance(percent, (float, int))
assert percent >= 0
assert percent <= 100
except (AssertionError, ValueError):
except ValueError:
should_raise = True
else:
if (
not isinstance(percent, (float, int))
or percent < 0
or percent > 100
):
should_raise = True
if should_raise:
raise WorkflowConfigError(
f"'percent' should be a float between 0 and 100: {f_signature}")

try:
secs = f_kwargs.get('secs', 0)
assert isinstance(secs, int)
except (AssertionError, ValueError):
except ValueError:
should_raise = True
else:
if not isinstance(secs, int):
should_raise = True

if should_raise:
raise WorkflowConfigError(
f"'secs' should be an integer: {f_signature}")

0 comments on commit b543af7

Please sign in to comment.