Skip to content

Commit bb67cfc

Browse files
committed
First support for applying @task to class methods
1 parent d6f935e commit bb67cfc

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

dreadnode/task.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,25 @@ def __post_init__(self) -> None:
128128
self.__name__ = getattr(self.func, "__name__", self.name)
129129
self.__doc__ = getattr(self.func, "__doc__", None)
130130

131+
def __get__(self, obj: t.Any, objtype: t.Any) -> "Task[P, R]":
132+
if obj is None:
133+
return self
134+
135+
bound_func = self.func.__get__(obj, objtype)
136+
137+
return Task(
138+
tracer=self.tracer,
139+
name=self.name,
140+
label=self.label,
141+
attributes=self.attributes,
142+
func=bound_func,
143+
scorers=[scorer.clone() for scorer in self.scorers],
144+
tags=self.tags.copy(),
145+
log_params=self.log_params,
146+
log_inputs=self.log_inputs,
147+
log_output=self.log_output,
148+
)
149+
131150
def _bind_args(self, *args: P.args, **kwargs: P.kwargs) -> dict[str, t.Any]:
132151
signature = inspect.signature(self.func)
133152
bound_args = signature.bind(*args, **kwargs)

0 commit comments

Comments
 (0)