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