This is an automated email from the ASF dual-hosted git repository.

phanikumv pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new af753c6468 Add `__doc__` property to `@task` (#42041)
af753c6468 is described below

commit af753c646842cc6284c8f0bf4eff79267a007c45
Author: fritz-astronomer <[email protected]>
AuthorDate: Sat Sep 7 00:54:55 2024 -0400

    Add `__doc__` property to `@task` (#42041)
    
    
    Co-authored-by: Ash Berlin-Taylor <[email protected]>
    Co-authored-by: Jed Cunningham 
<[email protected]>
---
 airflow/decorators/base.py      |  4 ++++
 tests/decorators/test_python.py | 16 ++++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/airflow/decorators/base.py b/airflow/decorators/base.py
index d743acbe50..e27c744b6e 100644
--- a/airflow/decorators/base.py
+++ b/airflow/decorators/base.py
@@ -334,6 +334,10 @@ class _TaskDecorator(ExpandableFactory, Generic[FParams, 
FReturn, OperatorSubcla
     is_teardown: bool = False
     on_failure_fail_dagrun: bool = False
 
+    @property
+    def __doc__(self):
+        return self.function.__doc__
+
     @multiple_outputs.default
     def _infer_multiple_outputs(self):
         if "return" not in self.function.__annotations__:
diff --git a/tests/decorators/test_python.py b/tests/decorators/test_python.py
index 401ad31f4f..96473518cc 100644
--- a/tests/decorators/test_python.py
+++ b/tests/decorators/test_python.py
@@ -871,6 +871,22 @@ def test_task_decorator_has_wrapped_attr():
     assert decorated_test_func.__wrapped__ is org_test_func, "__wrapped__ attr 
is not the original function"
 
 
+def test_task_decorator_has_doc_attr():
+    """
+    Test @task original underlying function docstring
+    through the __doc__ attribute.
+    """
+
+    def org_test_func():
+        """Docstring"""
+
+    decorated_test_func = task_decorator(org_test_func)
+    assert hasattr(decorated_test_func, "__doc__"), "decorated function should 
have __doc__ attribute"
+    assert (
+        decorated_test_func.__doc__ == org_test_func.__doc__
+    ), "__doc__ attr should be the original docstring"
+
+
 @pytest.mark.skip_if_database_isolation_mode  # Test is broken in db isolation 
mode
 def test_upstream_exception_produces_none_xcom(dag_maker, session):
     from airflow.exceptions import AirflowSkipException

Reply via email to