Improve contextvars.Context (#7052)

Similar changes to the ones @sobolevn made in #6942
This commit is contained in:
Alex Waygood
2022-01-27 15:33:53 +00:00
committed by GitHub
parent 97c490aec0
commit e01fc81497

View File

@@ -1,10 +1,12 @@
import sys
from typing import Any, Callable, ClassVar, Generic, Iterator, Mapping, TypeVar
from typing_extensions import ParamSpec
if sys.version_info >= (3, 9):
from types import GenericAlias
_T = TypeVar("_T")
_P = ParamSpec("_P")
class ContextVar(Generic[_T]):
def __init__(self, name: str, *, default: _T = ...) -> None: ...
@@ -31,8 +33,8 @@ def copy_context() -> Context: ...
# 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 run(self, callable: Callable[_P, _T], *args: _P.args, **kwargs: _P.kwargs) -> _T: ...
def copy(self) -> Context: ...
def __getitem__(self, key: ContextVar[Any]) -> Any: ...
def __getitem__(self, key: ContextVar[_T]) -> _T: ...
def __iter__(self) -> Iterator[ContextVar[Any]]: ...
def __len__(self) -> int: ...