Backport many ParamSpec-related changes to Python 2 (#7054)

This commit is contained in:
Alex Waygood
2022-01-27 15:57:26 +00:00
committed by GitHub
parent 5b39d07cd9
commit 2d8decd237
7 changed files with 21 additions and 8 deletions

View File

@@ -1,16 +1,18 @@
from types import TracebackType
from typing import IO, Any, Callable, ContextManager, Iterable, Iterator, Optional, Protocol, TypeVar
from typing_extensions import ParamSpec
_T = TypeVar("_T")
_T_co = TypeVar("_T_co", covariant=True)
_F = TypeVar("_F", bound=Callable[..., Any])
_P = ParamSpec("_P")
_ExitFunc = Callable[[Optional[type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool]
class GeneratorContextManager(ContextManager[_T_co]):
def __call__(self, func: _F) -> _F: ...
def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., ContextManager[_T]]: ...
def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, ContextManager[_T]]: ...
def nested(*mgr: ContextManager[Any]) -> ContextManager[Iterable[Any]]: ...
class _SupportsClose(Protocol):