-
Notifications
You must be signed in to change notification settings - Fork 5
Improve enums and add a generic enum_from_proto()
#82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Signed-off-by: Leandro Lucarella <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves enum handling by introducing a generic enum_from_proto function and making various enums unique, while deprecating their old from_proto methods.
- Introduces a generic enum_from_proto utility for converting protobuf enum values.
- Applies the @enum.unique decorator to enums and deprecates the from_proto methods.
- Adds missing component categories and updates Metric enum accordingly.
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/test_enum_proto.py | Adds tests for the new enum_from_proto utility |
| src/frequenz/client/common/microgrid/components/init.py | Updates enums with @enum.unique and adds new component categories; deprecates from_proto |
| src/frequenz/client/common/metric/init.py | Updates Metric enum with unique and deprecates from_proto method |
| src/frequenz/client/common/enum_proto.py | Introduces the generic enum_from_proto utility and updates its documentation |
Signed-off-by: Leandro Lucarella <[email protected]>
This needs a bump of the minimum `frequenz-api-common` to v0.6.1 as this category was added in that version. Signed-off-by: Leandro Lucarella <[email protected]>
|
@flora-hofmann-frequenz feel free to port these changes to the v0.x.x branch |
This function can convert any `int` to any `Enum`, with optional validation or forward-compatibility. Signed-off-by: Leandro Lucarella <[email protected]>
Recommend using the new `enum_from_proto()` instead. Signed-off-by: Leandro Lucarella <[email protected]>
This is to avoid errors in tests about duplicated `BaseId` prefixes. Signed-off-by: Leandro Lucarella <[email protected]>
Signed-off-by: Leandro Lucarella <[email protected]>
enum_from_proto()function.from_proto()