dash-extensions icon indicating copy to clipboard operation
dash-extensions copied to clipboard

`DataclassTransform` support for `list[DataclassModel]` annotations

Open joebeeson opened this issue 9 months ago • 1 comments

This pull request modifies the _try_load and _try_dump methods of the DataclassTransform to support annotations inside list type hints. The dump method is a bit "looser" as it doesn't use the callback's return annotation (it could?)

joebeeson avatar Apr 04 '25 21:04 joebeeson

@joebeeson The code looks good. I am a bit unsure if this is the right path to follow though. Is there any reason not just to define a new model (dataclass or basemodel) that holds a list of entries? That way, we can have the built-in serialization pipeline (e.g. Pydantic) do the heavy lifting, and we wouldn't need any custom code.

The proposed PR handles lists - but what about dicts? Or nested lists? Or ... All that complexity is already covered by e.g. Pydantic.

emilhe avatar Apr 05 '25 13:04 emilhe