Add context manager for contextvars.Token (3.14) (#13997)

This commit is contained in:
Max Muoto
2025-05-10 23:33:33 +02:00
committed by GitHub
parent 5ff32f377c
commit c4aa48a626
2 changed files with 7 additions and 5 deletions
+7 -1
View File
@@ -1,5 +1,6 @@
import sys
from collections.abc import Callable, Iterator, Mapping
from types import GenericAlias
from types import GenericAlias, TracebackType
from typing import Any, ClassVar, Generic, TypeVar, final, overload
from typing_extensions import ParamSpec, Self
@@ -35,6 +36,11 @@ class Token(Generic[_T]):
MISSING: ClassVar[object]
__hash__: ClassVar[None] # type: ignore[assignment]
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
if sys.version_info >= (3, 14):
def __enter__(self) -> Self: ...
def __exit__(
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
) -> None: ...
def copy_context() -> Context: ...