tmt icon indicating copy to clipboard operation
tmt copied to clipboard

Refactor serialization/deserialization helpers

Open therazix opened this issue 1 month ago • 1 comments

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

therazix avatar Nov 12 '25 12:11 therazix

Valid point, it will be resolved over time as we migrate from custom tmt.container.container decorator and implementation over to attrs/Pydatic.

happz avatar Nov 19 '25 09:11 happz