Skip to content

Commit f5420b0

Browse files
committed
Don't use unwrapped functions for execution in task()
1 parent ddf5f8f commit f5420b0

1 file changed

Lines changed: 28 additions & 10 deletions

File tree

dreadnode/main.py

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,15 @@
2727
from .exporters import FileExportConfig, FileMetricReader, FileSpanExporter
2828
from .score import Scorer, ScorerCallable, T
2929
from .task import P, R, Task
30-
from .tracing import JsonValue, RunSpan, Score, Span, TaskSpan, current_run_span, current_task_span
30+
from .tracing import (
31+
JsonValue,
32+
RunSpan,
33+
Score,
34+
Span,
35+
TaskSpan,
36+
current_run_span,
37+
current_task_span,
38+
)
3139
from .version import VERSION
3240

3341

@@ -127,7 +135,10 @@ def initialize(self) -> None:
127135
)
128136

129137
if self.local_dir is not False:
130-
config = FileExportConfig(base_path=self.local_dir, prefix=self.project + "-" if self.project else "")
138+
config = FileExportConfig(
139+
base_path=self.local_dir,
140+
prefix=self.project + "-" if self.project else "",
141+
)
131142
span_processors.append(BatchSpanProcessor(FileSpanExporter(config)))
132143
metric_readers.append(FileMetricReader(config))
133144

@@ -228,7 +239,8 @@ def task(
228239
name: str | None = None,
229240
tags: t.Sequence[str] | None = None,
230241
**attributes: t.Any,
231-
) -> t.Callable[[t.Callable[P, t.Awaitable[R]]], Task[P, R]]: ...
242+
) -> t.Callable[[t.Callable[P, t.Awaitable[R]]], Task[P, R]]:
243+
...
232244

233245
@t.overload
234246
def task(
@@ -238,7 +250,8 @@ def task(
238250
name: str | None = None,
239251
tags: t.Sequence[str] | None = None,
240252
**attributes: t.Any,
241-
) -> t.Callable[[t.Callable[P, t.Awaitable[R]]], Task[P, R]]: ...
253+
) -> t.Callable[[t.Callable[P, t.Awaitable[R]]], Task[P, R]]:
254+
...
242255

243256
def task(
244257
self,
@@ -249,21 +262,26 @@ def task(
249262
**attributes: t.Any,
250263
) -> t.Callable[[t.Callable[P, t.Awaitable[R]]], Task[P, R]]:
251264
def make_task(func: t.Callable[P, t.Awaitable[R]]) -> Task[P, R]:
252-
func = inspect.unwrap(func)
253-
254-
qualified_func_name = func_name = getattr(func, "__qualname__", getattr(func, "__name__", safe_repr(func)))
265+
unwrapped = inspect.unwrap(func)
266+
qualified_func_name = func_name = getattr(
267+
unwrapped,
268+
"__qualname__",
269+
getattr(unwrapped, "__name__", safe_repr(unwrapped)),
270+
)
255271

256272
with contextlib.suppress(Exception):
257-
qualified_func_name = f"{inspect.getmodule(func).__name__}.{func_name}" # type: ignore
273+
qualified_func_name = f"{inspect.getmodule(unwrapped).__name__}.{func_name}" # type: ignore
258274

259275
_name = name or qualified_func_name
260276

261277
_attributes = attributes or {}
262278
_attributes["code.function"] = func_name
263279
with contextlib.suppress(Exception):
264-
_attributes["code.lineno"] = func.__code__.co_firstlineno
280+
_attributes["code.lineno"] = unwrapped.__code__.co_firstlineno
265281
with contextlib.suppress(Exception):
266-
_attributes.update(get_filepath_attribute(inspect.getsourcefile(func))) # type: ignore
282+
_attributes.update(
283+
get_filepath_attribute(inspect.getsourcefile(unwrapped)) # type: ignore
284+
)
267285

268286
return Task(
269287
tracer=self._get_tracer(),

0 commit comments

Comments
 (0)