Philip MacMenamin
04/28/2022, 3:36 PMfrom prefect import task, Flow
from typing import Tuple
@task
def double_and_triple(x: int) -> Tuple[int, int]:
return x * 2, x * 3
with Flow("This works") as flow:
a = [1,2,3]
double, triple = double_and_triple.map(x=a)
Traceback (most recent call last):
File "test_mult_ret.py", line 11, in <module>
double, triple = double_and_triple.map(x=a)
File "/home/macmenaminpe/.local/lib/python3.8/site-packages/prefect/core/task.py", line 1034, in __iter__
raise TypeError(
TypeError: Task is not iterable. If your task returns multiple results, pass `nout` to the task decorator/constructor, or provide a `Tuple` return-type annotation to your task.
@task(nout=2)
Anna Geller
Philip MacMenamin
04/28/2022, 3:59 PMzip_task
task might be nicer.Kevin Kho
zip_task
is not quite the right concept. The double_and_triple
task returns a Tuple
so mapping returns a List[Tuple]
. So if you map over 10 items, you get 10 Tuples.
x, y = something
in Python means that iterable has 2 items. It assumed the output type is Tuple[List]