mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 13:04:46 +08:00
Improve contextvars.Context (#7052)
Similar changes to the ones @sobolevn made in #6942
This commit is contained in:
@@ -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: ...
|
||||
|
||||
Reference in New Issue
Block a user