Skip to content

Typehinting with quotes generates warnings #62945

@komjera

Description

@komjera

Apache Airflow version

3.1.7

If "Other Airflow 3 version" selected, which one?

No response

What happened?

Received warning

Cannot infer multiple_outputs for TaskFlow function 'dataframe_task' with forward type references that are not imported. (Error was name 'DataFrame' is not defined) category=UserWarning

when using quotes when typehinting with a type that is only imported during TYPE_CHECKING.

What you think should happen instead?

There should be no warning

How to reproduce

from typing import TYPE_CHECKING

from airflow.sdk import dag, task

if TYPE_CHECKING:
    from pandas import DataFrame


@task(task_id="df_task")
def dataframe_task() -> "DataFrame":
    import pandas as pd

    df = pd.DataFrame({"a": [1, 2, 3]})
    return df


@dag()
def simple_dag():
    _ = dataframe_task()


simple_dag()

Operating System

Debian GNU/Linux 12 (bookworm)

Versions of Apache Airflow Providers

apache-airflow-providers-standard==1.11.0
apache-airflow-providers-common-sql==1.30.4
apache-airflow-providers-microsoft-azure==12.10.3
apache-airflow-providers-microsoft-mssql==4.4.1

Deployment

Astronomer

Deployment details

Running locally using astro CLI and image astrocrpublic.azurecr.io/runtime:3.1-13-python-3.12

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corekind:bugThis is a clearly a bugneeds-triagelabel for new issues that we didn't triage yet

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions