I can of course convert the dict to the object manually, but just wondering whether flytekit could do this type of thing automatically.
t
thankful-minister-83577
02/05/2024, 10:53 PM
no unf. that is not possible right now.
thankful-minister-83577
02/05/2024, 10:53 PM
there was some interest in the latest contributor meetings to revamp this, but this hasn’t been prioritized at all.
s
steep-jackal-21573
02/06/2024, 8:37 AM
I see. Thank you.
steep-jackal-21573
02/06/2024, 8:38 AM
If it helps, I basically did something like:
Copy code
def to_named_tuple(name: str, data: Any) -> Any:
if isinstance(data, dict):
data = {key: to_named_tuple(key, value) for key, value in data.items()}
return namedtuple(name, data.keys())(**data)
if isinstance(data, list):
return [to_named_tuple(name, item) for item in data]
return data