https://flyte.org logo
#ask-the-community
Title
# ask-the-community
h

honnix

02/05/2024, 7:37 PM
Does flytekit support nested namedtuple like the following:
Copy code
class ExecutionExtra(NamedTuple):
    error: str

class Result(NamedTuple):
    execution_extra: ExecutionExtra
When I try to decode from the following proto to `Result`:
Copy code
...
    "executionExtra": {
        "scalar": {
          "generic": {
            "error": "error"
          }
        }
      },
...
I got
execution_extra
as a dict instead of a proper instance of
ExecutionExtra
.
I can of course convert the dict to the object manually, but just wondering whether flytekit could do this type of thing automatically.
y

Yee

02/05/2024, 10:53 PM
no unf. that is not possible right now.
there was some interest in the latest contributor meetings to revamp this, but this hasn’t been prioritized at all.
h

honnix

02/06/2024, 8:37 AM
I see. Thank you.
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