From e942284c34938af87cb23e6051f218e458268af7 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sun, 16 May 2021 12:26:55 -0700 Subject: [PATCH 1/3] use ParamSpec for @contextmanager --- stdlib/contextlib.pyi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index 3cadf91df90f..f7954878de7e 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -13,7 +13,7 @@ from typing import ( TypeVar, overload, ) -from typing_extensions import Protocol +from typing_extensions import ParamSpec, Protocol AbstractContextManager = ContextManager if sys.version_info >= (3, 7): @@ -23,6 +23,7 @@ _T = TypeVar("_T") _T_co = TypeVar("_T_co", covariant=True) _T_io = TypeVar("_T_io", bound=Optional[IO[str]]) _F = TypeVar("_F", bound=Callable[..., Any]) +_P = ParamSpec("_P") _ExitFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], bool] _CM_EF = TypeVar("_CM_EF", ContextManager[Any], _ExitFunc) @@ -30,10 +31,10 @@ _CM_EF = TypeVar("_CM_EF", ContextManager[Any], _ExitFunc) class _GeneratorContextManager(ContextManager[_T_co]): def __call__(self, func: _F) -> _F: ... -def contextmanager(func: Callable[..., Iterator[_T]]) -> Callable[..., _GeneratorContextManager[_T]]: ... +def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ... if sys.version_info >= (3, 7): - def asynccontextmanager(func: Callable[..., AsyncIterator[_T]]) -> Callable[..., AsyncContextManager[_T]]: ... + def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, AsyncContextManager[_T]]: ... class _SupportsClose(Protocol): def close(self) -> None: ... From baf31676f2bc019d3e8ddec74075a9b918276fba Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 14 Jun 2021 07:02:45 -0700 Subject: [PATCH 2/3] Update contextlib.pyi --- stdlib/contextlib.pyi | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index f7954878de7e..b2052c413aa5 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -31,10 +31,11 @@ _CM_EF = TypeVar("_CM_EF", ContextManager[Any], _ExitFunc) class _GeneratorContextManager(ContextManager[_T_co]): def __call__(self, func: _F) -> _F: ... -def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ... +# type: ignore to deal with incomplete ParamSpec support in mypy +def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ... # type: ignore if sys.version_info >= (3, 7): - def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, AsyncContextManager[_T]]: ... + def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, AsyncContextManager[_T]]: ... # type: ignore class _SupportsClose(Protocol): def close(self) -> None: ... From d347f2d89d42bc3f0f9f367de86c4e45b0c8010a Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Mon, 14 Jun 2021 07:11:34 -0700 Subject: [PATCH 3/3] remove : --- stdlib/contextlib.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index b2052c413aa5..29951a248911 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -31,7 +31,7 @@ _CM_EF = TypeVar("_CM_EF", ContextManager[Any], _ExitFunc) class _GeneratorContextManager(ContextManager[_T_co]): def __call__(self, func: _F) -> _F: ... -# type: ignore to deal with incomplete ParamSpec support in mypy +# type ignore to deal with incomplete ParamSpec support in mypy def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ... # type: ignore if sys.version_info >= (3, 7):