We could use special values to represent INFINITE and INSTANTANEOUS for the Dispatch.duration field, so the code gets more readable (without the need for comments) and more type-safe.
We could set the type of duration: timedelta | Duration where duration is a enum for example, then we can also use match like this:
match dispatch.duration:
case Duration.INFINITE: ...
case Duration.INSTANTANEOUS: ...
case timedelta(): ... (here we know it is > 0)
case unexpected: assert_never(unexpected)
Taking it even a bit further, we could have a PositiveTimedelta object that even guarantee the time is positive.
Originally posted by @llucax in frequenz-floss/frequenz-dispatch-python#54 (comment)
We could use special values to represent
INFINITEandINSTANTANEOUSfor theDispatch.durationfield, so the code gets more readable (without the need for comments) and more type-safe.We could set the type of
duration: timedelta | Durationwhere duration is a enum for example, then we can also usematchlike this:Taking it even a bit further, we could have a
PositiveTimedeltaobject that even guarantee the time is positive.Originally posted by @llucax in frequenz-floss/frequenz-dispatch-python#54 (comment)