Skip to content

Commit 8f4c43f

Browse files
committed
Move validation to the top
Better to fail as soon as possible. Signed-off-by: Leandro Lucarella <[email protected]>
1 parent 5fc16ef commit 8f4c43f

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

src/frequenz/channels/util/_timer.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,11 @@ def __init__(
417417
ValueError: if `interval` is not positive or is smaller than 1
418418
microsecond.
419419
"""
420+
if interval < timedelta(microseconds=1):
421+
raise ValueError(
422+
f"The `interval` must be positive and at least 1 microsecond, not {interval}"
423+
)
424+
420425
self._interval: int = _to_microseconds(interval)
421426
"""The time to between timer ticks."""
422427

@@ -464,12 +469,6 @@ def __init__(
464469
to wait again.
465470
"""
466471

467-
if self._interval <= 0:
468-
raise ValueError(
469-
"The `interval` must be positive and at least 1 microsecond, "
470-
f"not {interval} ({self._interval} microseconds)"
471-
)
472-
473472
if auto_start:
474473
self.reset()
475474

0 commit comments

Comments
 (0)