You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "ashb (via GitHub)" <gi...@apache.org> on 2023/02/10 14:26:44 UTC

[GitHub] [airflow] ashb commented on a diff in pull request #29445: Better handle forward type definitions in `@task.python` for multiple output

ashb commented on code in PR #29445:
URL: https://github.com/apache/airflow/pull/29445#discussion_r1102828840


##########
airflow/decorators/base.py:
##########
@@ -296,7 +297,20 @@ class _TaskDecorator(ExpandableFactory, Generic[FParams, FReturn, OperatorSubcla
     @multiple_outputs.default
     def _infer_multiple_outputs(self):
         try:
-            return_type = typing_extensions.get_type_hints(self.function).get("return", Any)
+            # We only care about the return annotation, not anything about the parameters
+            def fake():
+                ...
+
+            fake.__annotations__ = {"return": self.function.__annotations__["return"]}
+
+            return_type = typing_extensions.get_type_hints(fake, self.function.__globals__).get("return", Any)
+        except NameError as e:
+            warnings.warn(
+                "Cannot infer multiple_outputs with forward type references that are not imported. "

Review Comment:
   Oh yes good call.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org