tmt
tmt copied to clipboard
Refactor serialization/deserialization helpers
In some cases, we use standalone helper functions for field serialization/deserialization to work around circular imports: https://github.com/teemtee/tmt/blob/01d7ff0e4ba84e6ad6666cb4761f53cc33588ac5/tmt/result.py#L158-L163
This approach works but could be improved. One approach could be to provide some decorator-based interface:
@container
class MyData:
my_field: str
@my_field.serialize
def _my_field_serialize(self):
...
Or we could make the fields accept wrapper classes instead of lambda functions.
Related comment: https://github.com/teemtee/tmt/pull/4208#discussion_r2510326703
Valid point, it will be resolved over time as we migrate from custom tmt.container.container decorator and implementation over to attrs/Pydatic.