1111# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212# See the License for the specific language governing permissions and
1313# limitations under the License.
14- from contextvars import ContextVar
14+
15+ from __future__ import annotations
16+
17+ from contextvars import ContextVar , Token
1518
1619from opentelemetry .context .context import Context , _RuntimeContext
1720
@@ -28,7 +31,7 @@ def __init__(self) -> None:
2831 self ._CONTEXT_KEY , default = Context ()
2932 )
3033
31- def attach (self , context : Context ) -> object :
34+ def attach (self , context : Context ) -> Token [ Context ] :
3235 """Sets the current `Context` object. Returns a
3336 token that can be used to reset to the previous `Context`.
3437
@@ -41,13 +44,13 @@ def get_current(self) -> Context:
4144 """Returns the current `Context` object."""
4245 return self ._current_context .get ()
4346
44- def detach (self , token : object ) -> None :
47+ def detach (self , token : Token [ Context ] ) -> None :
4548 """Resets Context to a previous value
4649
4750 Args:
4851 token: A reference to a previous Context.
4952 """
50- self ._current_context .reset (token ) # type: ignore
53+ self ._current_context .reset (token )
5154
5255
5356__all__ = ["ContextVarsRuntimeContext" ]
0 commit comments