From a0f84011db77e34f289c5a860d8a6156d6a79db9 Mon Sep 17 00:00:00 2001 From: mao3267 Date: Thu, 24 Oct 2024 09:34:49 +0800 Subject: [PATCH] update comments in _make_dataclass_serializable Signed-off-by: mao3267 --- flytekit/core/type_engine.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/flytekit/core/type_engine.py b/flytekit/core/type_engine.py index 900afa8562..90bcb877e8 100644 --- a/flytekit/core/type_engine.py +++ b/flytekit/core/type_engine.py @@ -673,6 +673,18 @@ def _fix_structured_dataset_type(self, python_type: Type[T], python_val: typing. def _make_dataclass_serializable(self, python_val: T, python_type: Type[T]) -> typing.Any: """ If any field inside the dataclass is flyte type, we should use flyte type transformer for that field. + Since other types are already serializable, this function is intended for using strings instead of directly creating Flyte files and directories in the dataclass. + An example shows the lifecycle: + + @dataclass + class DC: + ff: FlyteFile + + @task + def t1() -> DC: + return DC(ff="s3://path") + + Lifecycle: DC(ff="s3://path") -> to_literal() -> DC(ff=FlyteFile(path="s3://path")) -> msgpack -> to_python_value() -> DC(ff=FlyteFile(path="s3://path")) """ from flytekit.types.directory import FlyteDirectory from flytekit.types.file import FlyteFile