Skip to content

Commit

Permalink
Add __wrapped__ property to _TaskDecorator (#23830)
Browse files Browse the repository at this point in the history
Co-authored-by: Sanjay Pillai <sanjaypillai11 [at] gmail.com>
  • Loading branch information
snjypl committed May 23, 2022
1 parent a844565 commit a71e4b7
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion airflow/decorators/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ def __call__(self, *args, **kwargs) -> XComArg:
op.doc_md = self.function.__doc__
return XComArg(op)

@property
def __wrapped__(self) -> Function:
return self.function

@cached_property
def function_signature(self):
return inspect.signature(self.function)
Expand Down Expand Up @@ -495,6 +499,10 @@ class Task(Generic[Function]):

function: Function

@property
def __wrapped__(self) -> Function:
...

def expand(self, **kwargs: "Mappable") -> XComArg:
...

Expand Down Expand Up @@ -527,7 +535,7 @@ def task_decorator_factory(
**kwargs,
) -> TaskDecorator:
"""
A factory that generates a wrapper that raps a function into an Airflow operator.
A factory that generates a wrapper that wraps a function into an Airflow operator.
Accepts kwargs for operator kwarg. Can be reused in a single DAG.
:param python_callable: Function to decorate
Expand Down
17 changes: 17 additions & 0 deletions tests/decorators/test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,3 +738,20 @@ def fn(arg1, arg2):

assert op.op_kwargs['arg1'] == "{{ ds }}"
assert op.op_kwargs['arg2'] == "fn"


def test_task_decorator_has_wrapped_attr():
"""
Test @task original underlying function is accessible
through the __wrapped__ attribute.
"""

def org_test_func():
pass

decorated_test_func = task_decorator(org_test_func)

assert hasattr(
decorated_test_func, '__wrapped__'
), "decorated function does not have __wrapped__ attribute"
assert decorated_test_func.__wrapped__ is org_test_func, "__wrapped__ attr is not the original function"

0 comments on commit a71e4b7

Please sign in to comment.