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 2021/03/12 15:34:13 UTC

[GitHub] [airflow] kaxil commented on a change in pull request #14709: Refactor Taskflow decorator for extensibility

kaxil commented on a change in pull request #14709:
URL: https://github.com/apache/airflow/pull/14709#discussion_r593261669



##########
File path: airflow/decorators/base.py
##########
@@ -0,0 +1,194 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+import functools
+import inspect
+import re
+from inspect import signature
+from typing import Any, Callable, Dict, Optional, Tuple, TypeVar, cast
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.models.dag import DAG, DagContext
+from airflow.models.xcom_arg import XComArg
+from airflow.utils.decorators import apply_defaults
+from airflow.utils.task_group import TaskGroup, TaskGroupContext
+
+
+class BaseDecoratedOperator(BaseOperator):
+    """
+    Wraps a Python callable and captures args/kwargs when called for execution.
+
+    :param python_callable: A reference to an object that is callable
+    :type python_callable: python callable
+    :param op_kwargs: a dictionary of keyword arguments that will get unpacked
+        in your function (templated)
+    :type op_kwargs: dict
+    :param op_args: a list of positional arguments that will get unpacked when
+        calling your callable (templated)
+    :type op_args: list
+    :param multiple_outputs: if set, function return value will be
+        unrolled to multiple XCom values. Dict will unroll to xcom values with keys as keys.
+        Defaults to False.
+    :type multiple_outputs: bool
+    """
+
+    template_fields = ('op_args', 'op_kwargs')
+    template_fields_renderers = {"op_args": "py", "op_kwargs": "py"}
+
+    # since we won't mutate the arguments, we should just do the shallow copy
+    # there are some cases we can't deepcopy the objects (e.g protobuf).
+    shallow_copy_attrs = ('python_callable',)

Review comment:
       Do we need this in base decorator?
   
   `op_args`, `op_kwargs` and `python_callable` are just fields of a `PythonOperator` for now. If we want to extend it to `@task.docker`, we might either want to add this to the docker / KPO or do we have a different plan




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