Skip to content

Support Tuple[foo, bar] type hints on @task decorated functions #15813

Description

@MatrixManAtYrService

Description

#8996 described the use of type hints to indicate multiple outputs for tasks created with @task. The Dict type hint was delivered in #10349. Tuple was left out of that PR (see here).

I'm creating this issue so that we can discuss whether Tuple support should be added (described here), or whether its omission from #10349 means that it shouldn't be added at all.

The Argument

I think that its omission leaves the user in an awkward position. The TaskFlow mindset extends very naturally to tuples:

@task
def return_two() -> Tuple[str, int]:
    return "nine", 6

@dag
do_stuff():
    a, b = return_two()
    print_one(a) 
    print_another(b)

Without them you need extra object references to structure your dag. You also need extra names to explicitly pull the xcoms that you implicitly pushed, which feels a bit lopsided. Without tuple support, I guess it would go something like this:

@task
def return_two() -> Dict[str, str]:
    return {"one": "nine", "another": "6"}

@dag
def do_stuff():

    a = return_two()
    b = print_one("{{ ti.xcom_pull(key='one') }}")
    c = print_another("{{ int(ti.xcom_pull(key='another')) }}")

    a >> b
    a >> c

It just feels like it's coaxing you away from using TaskFlow, which is a bummer because TaskFlow is cool.

Metadata

Metadata

Assignees

No one assigned

    Labels

    AIP-31Task Flow API for nicer DAG definitionarea:corekind:featureFeature Requests

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions