You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/11/11 23:54:00 UTC

[GitHub] [airflow] AndersonReyes commented on a change in pull request #10349: infer multiple_output from return type annotation

AndersonReyes commented on a change in pull request #10349:
URL: https://github.com/apache/airflow/pull/10349#discussion_r521711017



##########
File path: airflow/operators/python.py
##########
@@ -255,6 +255,16 @@ def task(
     :type multiple_outputs: bool
 
     """
+    # try to infer from  type annotation
+    if python_callable and multiple_outputs is None:
+        sig = signature(python_callable).return_annotation
+        ttype = getattr(sig, "__origin__", None)
+
+        if sig != inspect.Signature.empty and ttype in (dict, Dict):
+            multiple_outputs = True
+
+    # in case its still none, then set False here
+    multiple_outputs = multiple_outputs or False

Review comment:
       I'll do the patch suggestion you have above, removing the if statement would set it to false anyways so yeah the line is not needed

##########
File path: docs/tutorial_taskflow_api.rst
##########
@@ -144,6 +144,22 @@ the dependencies as shown below.
     :end-before: [END main_flow]
 
 
+Multiple outputs inference
+--------------------------
+Tasks can also infer multiple outputs by using dict python typing.
+
+.. code-block:: python
+
+    @task
+    def identity_dict(x: int, y: int) -> Dict[str, int]:
+        return {"x": x, "y": y}
+
+By using the typing ``Dict`` for the function return type, the ``multiple_outputs`` parameter
+is automatically set to true.
+
+Not, If you manually set the ``multiple_outputs`` parameter the inference is disabled and

Review comment:
       nah def a typo 

##########
File path: airflow/operators/python.py
##########
@@ -255,6 +255,16 @@ def task(
     :type multiple_outputs: bool
 
     """
+    # try to infer from  type annotation
+    if python_callable and multiple_outputs is None:
+        sig = signature(python_callable).return_annotation
+        ttype = getattr(sig, "__origin__", None)
+
+        if sig != inspect.Signature.empty and ttype in (dict, Dict):
+            multiple_outputs = True

Review comment:
       👍 




----------------------------------------------------------------
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.

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