Use ParamSpec for contextvars.Context.run (#6940)

This commit is contained in:
Nikita Sobolev
2022-01-18 01:00:21 +03:00
committed by GitHub
parent e558fedf76
commit 18d746b6b0

View File

@@ -1,11 +1,13 @@
import sys
from typing import Any, Callable, ClassVar, Generic, Iterator, Mapping, TypeVar, overload
from typing_extensions import ParamSpec
if sys.version_info >= (3, 9):
from types import GenericAlias
_T = TypeVar("_T")
_D = TypeVar("_D")
_P = ParamSpec("_P")
class ContextVar(Generic[_T]):
def __init__(self, name: str, *, default: _T = ...) -> None: ...
@@ -39,7 +41,7 @@ class Context(Mapping[ContextVar[Any], Any]):
def get(self, __key: ContextVar[Any]) -> Any | None: ...
@overload
def get(self, __key: ContextVar[Any], __default: Any | None) -> Any: ...
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 __iter__(self) -> Iterator[ContextVar[Any]]: ...