Skip to content

Commit a71e4b7

Browse files
authored
Add __wrapped__ property to _TaskDecorator (#23830)
Co-authored-by: Sanjay Pillai <sanjaypillai11 [at] gmail.com>
1 parent a844565 commit a71e4b7

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

airflow/decorators/base.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,10 @@ def __call__(self, *args, **kwargs) -> XComArg:
267267
op.doc_md = self.function.__doc__
268268
return XComArg(op)
269269

270+
@property
271+
def __wrapped__(self) -> Function:
272+
return self.function
273+
270274
@cached_property
271275
def function_signature(self):
272276
return inspect.signature(self.function)
@@ -495,6 +499,10 @@ class Task(Generic[Function]):
495499

496500
function: Function
497501

502+
@property
503+
def __wrapped__(self) -> Function:
504+
...
505+
498506
def expand(self, **kwargs: "Mappable") -> XComArg:
499507
...
500508

@@ -527,7 +535,7 @@ def task_decorator_factory(
527535
**kwargs,
528536
) -> TaskDecorator:
529537
"""
530-
A factory that generates a wrapper that raps a function into an Airflow operator.
538+
A factory that generates a wrapper that wraps a function into an Airflow operator.
531539
Accepts kwargs for operator kwarg. Can be reused in a single DAG.
532540
533541
:param python_callable: Function to decorate

tests/decorators/test_python.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -738,3 +738,20 @@ def fn(arg1, arg2):
738738

739739
assert op.op_kwargs['arg1'] == "{{ ds }}"
740740
assert op.op_kwargs['arg2'] == "fn"
741+
742+
743+
def test_task_decorator_has_wrapped_attr():
744+
"""
745+
Test @task original underlying function is accessible
746+
through the __wrapped__ attribute.
747+
"""
748+
749+
def org_test_func():
750+
pass
751+
752+
decorated_test_func = task_decorator(org_test_func)
753+
754+
assert hasattr(
755+
decorated_test_func, '__wrapped__'
756+
), "decorated function does not have __wrapped__ attribute"
757+
assert decorated_test_func.__wrapped__ is org_test_func, "__wrapped__ attr is not the original function"

0 commit comments

Comments
 (0)