apache / apache/airflow

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

Open
#15,813 0 comments 0 reactions 0 assignees View on GitHub
AIP-31 area:core kind:feature
Dominant language
Python
Stars
46.9k
Forks
17.8k
Avg merge
2d 9h
Merged PRs (30d)
472

Description

**Description**

https://github.com/apache/airflow/issues/8996 described the use of type hints to indicate multiple outputs for tasks created with `@task`. The `Dict` type hint was delivered in https://github.com/apache/airflow/pull/10349. `Tuple` was left out of that PR (see [here](https://github.com/apache/airflow/pull/10349#issuecomment-680918458)).

I'm creating this issue so that we can discuss whether `Tuple` support should be added (described [here](https://github.com/apache/airflow/pull/10349#issuecomment-674477268)), or whether its omission from https://github.com/apache/airflow/pull/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:

```python
@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:

```python
@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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.