Skip to content

Commit c4aa48a

Browse files
authored
Add context manager for contextvars.Token (3.14) (#13997)
1 parent 5ff32f3 commit c4aa48a

2 files changed

Lines changed: 7 additions & 5 deletions

File tree

stdlib/@tests/stubtest_allowlists/py314.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ _asyncio.all_tasks
66
_asyncio.future_add_to_awaited_by
77
_asyncio.future_discard_from_awaited_by
88
_compression
9-
_contextvars.Token.__enter__
10-
_contextvars.Token.__exit__
119
_ctypes.POINTER
1210
_ctypes.byref
1311
_ctypes.pointer
@@ -92,8 +90,6 @@ concurrent.futures.thread._worker
9290
configparser.__all__
9391
configparser.InvalidWriteError
9492
configparser.UnnamedSectionDisabledError
95-
contextvars.Token.__enter__
96-
contextvars.Token.__exit__
9793
ctypes.POINTER
9894
ctypes.byref
9995
ctypes.memoryview_at

stdlib/_contextvars.pyi

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import sys
12
from collections.abc import Callable, Iterator, Mapping
2-
from types import GenericAlias
3+
from types import GenericAlias, TracebackType
34
from typing import Any, ClassVar, Generic, TypeVar, final, overload
45
from typing_extensions import ParamSpec, Self
56

@@ -35,6 +36,11 @@ class Token(Generic[_T]):
3536
MISSING: ClassVar[object]
3637
__hash__: ClassVar[None] # type: ignore[assignment]
3738
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
39+
if sys.version_info >= (3, 14):
40+
def __enter__(self) -> Self: ...
41+
def __exit__(
42+
self, exc_type: type[BaseException] | None, exc_value: BaseException | None, traceback: TracebackType | None
43+
) -> None: ...
3844

3945
def copy_context() -> Context: ...
4046

0 commit comments

Comments
 (0)