11
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
- from contextvars import ContextVar
14
+
15
+ from __future__ import annotations
16
+
17
+ from contextvars import ContextVar , Token
15
18
16
19
from opentelemetry .context .context import Context , _RuntimeContext
17
20
@@ -28,7 +31,7 @@ def __init__(self) -> None:
28
31
self ._CONTEXT_KEY , default = Context ()
29
32
)
30
33
31
- def attach (self , context : Context ) -> object :
34
+ def attach (self , context : Context ) -> Token [ Context ] :
32
35
"""Sets the current `Context` object. Returns a
33
36
token that can be used to reset to the previous `Context`.
34
37
@@ -41,13 +44,13 @@ def get_current(self) -> Context:
41
44
"""Returns the current `Context` object."""
42
45
return self ._current_context .get ()
43
46
44
- def detach (self , token : object ) -> None :
47
+ def detach (self , token : Token [ Context ] ) -> None :
45
48
"""Resets Context to a previous value
46
49
47
50
Args:
48
51
token: A reference to a previous Context.
49
52
"""
50
- self ._current_context .reset (token ) # type: ignore
53
+ self ._current_context .reset (token )
51
54
52
55
53
56
__all__ = ["ContextVarsRuntimeContext" ]
0 commit comments