Skip to content

Commit bfe0b06

Browse files
add stub for contextvars.pyi (#1968)
Part of #1965.
1 parent 89cbd47 commit bfe0b06

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

stdlib/3.7/contextvars.pyi

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from typing import Any, Callable, ClassVar, Generic, Mapping, TypeVar, Union
2+
3+
_T = TypeVar('_T')
4+
5+
class ContextVar(Generic[_T]):
6+
def __init__(self, name: str, *, default: _T = ...) -> None: ...
7+
@property
8+
def name(self) -> str: ...
9+
def get(self, default: _T = ...) -> _T: ...
10+
def set(self, value: _T) -> Token[_T]: ...
11+
def reset(self, token: Token[_T]) -> None: ...
12+
13+
class Token(Generic[_T]):
14+
@property
15+
def var(self) -> ContextVar[_T]: ...
16+
@property
17+
def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express
18+
MISSING: ClassVar[object]
19+
20+
def copy_context() -> Context: ...
21+
22+
# It doesn't make sense to make this generic, because for most Contexts each ContextVar will have
23+
# a different value.
24+
class Context(Mapping[ContextVar[Any], Any]):
25+
def __init__(self) -> None: ...
26+
def run(self, callable: Callable[..., _T], *args: Any, **kwargs: Any) -> _T: ...
27+
def copy(self) -> Context: ...

0 commit comments

Comments
 (0)