massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-pyright / node_modules / pyright / dist / typeshed-fallback / stubs / contextvars / contextvars.pyi
1 import sys
2 from typing import Any, Callable, ClassVar, Generic, Iterator, Mapping, TypeVar
3
4 if sys.version_info >= (3, 9):
5     from types import GenericAlias
6
7 _T = TypeVar("_T")
8
9 class ContextVar(Generic[_T]):
10     def __init__(self, name: str, *, default: _T = ...) -> None: ...
11     @property
12     def name(self) -> str: ...
13     def get(self, default: _T = ...) -> _T: ...
14     def set(self, value: _T) -> Token[_T]: ...
15     def reset(self, token: Token[_T]) -> None: ...
16     if sys.version_info >= (3, 9):
17         def __class_getitem__(cls, item: Any) -> GenericAlias: ...
18
19 class Token(Generic[_T]):
20     @property
21     def var(self) -> ContextVar[_T]: ...
22     @property
23     def old_value(self) -> Any: ...  # returns either _T or MISSING, but that's hard to express
24     MISSING: ClassVar[object]
25     if sys.version_info >= (3, 9):
26         def __class_getitem__(cls, item: Any) -> GenericAlias: ...
27
28 def copy_context() -> Context: ...
29
30 # It doesn't make sense to make this generic, because for most Contexts each ContextVar will have
31 # a different value.
32 class Context(Mapping[ContextVar[Any], Any]):
33     def __init__(self) -> None: ...
34     def run(self, callable: Callable[..., _T], *args: Any, **kwargs: Any) -> _T: ...
35     def copy(self) -> Context: ...
36     def __getitem__(self, key: ContextVar[Any]) -> Any: ...
37     def __iter__(self) -> Iterator[ContextVar[Any]]: ...
38     def __len__(self) -> int: ...