Does flytekit support nested namedtuple like the f...
# ask-the-community
h
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
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
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