Skip to content

Consider adding a Duration enum with INFINITE and INSTANTANEOUS #93

@llucax

Description

@llucax

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions