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

This commit is contained in:
Max Muoto
2025-05-10 16:33:33 -05:00
committed by GitHub
parent 5ff32f377c
commit c4aa48a626
2 changed files with 7 additions and 5 deletions
@@ -6,8 +6,6 @@ _asyncio.all_tasks
_asyncio.future_add_to_awaited_by
_asyncio.future_discard_from_awaited_by
_compression
_contextvars.Token.__enter__
_contextvars.Token.__exit__
_ctypes.POINTER
_ctypes.byref
_ctypes.pointer
@@ -92,8 +90,6 @@ concurrent.futures.thread._worker
configparser.__all__
configparser.InvalidWriteError
configparser.UnnamedSectionDisabledError
contextvars.Token.__enter__
contextvars.Token.__exit__
ctypes.POINTER
ctypes.byref
ctypes.memoryview_at
+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: ...