Enable contextvars stubs (PY-39618, PY-39976)

GitOrigin-RevId: b4244a417e290607b5c36c7b649ee1b602da2735
This commit is contained in:
Semyon Proshev
2020-01-10 12:40:13 +00:00
committed by intellij-monorepo-bot
parent b1fea5545f
commit 0d9826d746
3 changed files with 61 additions and 0 deletions
@@ -0,0 +1,30 @@
from typing import Any, Callable, ClassVar, Generic, Iterator, Mapping, TypeVar
_T = TypeVar('_T')
class ContextVar(Generic[_T]):
def __init__(self, name: str, *, default: _T = ...) -> None: ...
@property
def name(self) -> str: ...
def get(self, default: _T = ...) -> _T: ...
def set(self, value: _T) -> Token[_T]: ...
def reset(self, token: Token[_T]) -> None: ...
class Token(Generic[_T]):
@property
def var(self) -> ContextVar[_T]: ...
@property
def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express
MISSING: ClassVar[object]
def copy_context() -> Context: ...
# It doesn't make sense to make this generic, because for most Contexts each ContextVar will have
# a different value.
class Context(Mapping[ContextVar[Any], Any]):
def __init__(self) -> None: ...
def run(self, callable: Callable[..., _T], *args: Any, **kwargs: Any) -> _T: ...
def copy(self) -> Context: ...
def __getitem__(self, key: ContextVar[Any]) -> Any: ...
def __iter__(self) -> Iterator[ContextVar[Any]]: ...
def __len__(self) -> int: ...
+30
View File
@@ -0,0 +1,30 @@
from typing import Any, Callable, ClassVar, Generic, Iterator, Mapping, TypeVar
_T = TypeVar('_T')
class ContextVar(Generic[_T]):
def __init__(self, name: str, *, default: _T = ...) -> None: ...
@property
def name(self) -> str: ...
def get(self, default: _T = ...) -> _T: ...
def set(self, value: _T) -> Token[_T]: ...
def reset(self, token: Token[_T]) -> None: ...
class Token(Generic[_T]):
@property
def var(self) -> ContextVar[_T]: ...
@property
def old_value(self) -> Any: ... # returns either _T or MISSING, but that's hard to express
MISSING: ClassVar[object]
def copy_context() -> Context: ...
# It doesn't make sense to make this generic, because for most Contexts each ContextVar will have
# a different value.
class Context(Mapping[ContextVar[Any], Any]):
def __init__(self) -> None: ...
def run(self, callable: Callable[..., _T], *args: Any, **kwargs: Any) -> _T: ...
def copy(self) -> Context: ...
def __getitem__(self, key: ContextVar[Any]) -> Any: ...
def __iter__(self) -> Iterator[ContextVar[Any]]: ...
def __len__(self) -> int: ...
@@ -36,6 +36,7 @@ val whiteList = setOf(
"builtins",
"collections",
"concurrent",
"contextvars",
"cPickle",
"crypt",
"ctypes",