Skip to content

Commit b79bd8e

Browse files
committed
fix: improve type hinting for current_trace_id in request_interface.py
1 parent b7a1380 commit b79bd8e

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

audiostack/helpers/request_interface.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import contextlib
2-
import contextvars
2+
from contextvars import ContextVar
33
import json
44
import shutil
55
from typing import Any, Callable, Dict, Generator, Optional, Union
@@ -9,7 +9,9 @@
99
import audiostack
1010
from audiostack.helpers.request_types import RequestTypes
1111

12-
_current_trace_id = contextvars.ContextVar("current_trace_id", default=None)
12+
_current_trace_id: ContextVar[Optional[str]] = ContextVar(
13+
"current_trace_id", default=None
14+
)
1315

1416

1517
def remove_empty(data: Any) -> Any:
@@ -161,9 +163,7 @@ def download_url(cls, url: str, name: str, destination: str) -> None:
161163

162164
@contextlib.contextmanager
163165
def use_trace(trace_id: str) -> Generator[None, None, None]:
164-
# This is a workaround to give correct type hints to the context manager but follow ContextVar's .set() method signature
165-
any_typed_trace_id: Any = trace_id
166-
token = _current_trace_id.set(any_typed_trace_id)
166+
token = _current_trace_id.set(trace_id)
167167
try:
168168
yield
169169
finally:

0 commit comments

Comments
 (0)