From 16db3dcf86edcdc4b06457aa42f7747a297aafe1 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Fri, 16 Jul 2021 08:31:26 +0100 Subject: [PATCH 1/4] resync from typeshed --- contextlib2/__init__.pyi | 13 +++++------ ...10_contextlib_pyi_to_contextlib2_pyi.patch | 22 +++++++++---------- 2 files changed, 16 insertions(+), 19 deletions(-) diff --git a/contextlib2/__init__.pyi b/contextlib2/__init__.pyi index 60c43fa..4549200 100644 --- a/contextlib2/__init__.pyi +++ b/contextlib2/__init__.pyi @@ -2,6 +2,7 @@ # https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE import sys +from _typeshed import Self from types import TracebackType from typing import ( IO, @@ -80,16 +81,14 @@ class redirect_stderr(ContextManager[_T_io]): class ContextDecorator: def __call__(self, func: _F) -> _F: ... -_U = TypeVar("_U", bound=ExitStack) - class ExitStack(ContextManager[ExitStack]): def __init__(self) -> None: ... def enter_context(self, cm: ContextManager[_T]) -> _T: ... def push(self, exit: _CM_EF) -> _CM_EF: ... def callback(self, callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ... - def pop_all(self: _U) -> _U: ... + def pop_all(self: Self) -> Self: ... def close(self) -> None: ... - def __enter__(self: _U) -> _U: ... + def __enter__(self: Self) -> Self: ... def __exit__( self, __exc_type: Optional[Type[BaseException]], @@ -98,8 +97,6 @@ class ExitStack(ContextManager[ExitStack]): ) -> bool: ... if True: - _S = TypeVar("_S", bound=AsyncExitStack) - _ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]] _CallbackCoroFunc = Callable[..., Awaitable[Any]] _ACM_EF = TypeVar("_ACM_EF", AsyncContextManager[Any], _ExitCoroFunc) @@ -111,9 +108,9 @@ if True: def push_async_exit(self, exit: _ACM_EF) -> _ACM_EF: ... def callback(self, callback: Callable[..., Any], *args: Any, **kwds: Any) -> Callable[..., Any]: ... def push_async_callback(self, callback: _CallbackCoroFunc, *args: Any, **kwds: Any) -> _CallbackCoroFunc: ... - def pop_all(self: _S) -> _S: ... + def pop_all(self: Self) -> Self: ... def aclose(self) -> Awaitable[None]: ... - def __aenter__(self: _S) -> Awaitable[_S]: ... + def __aenter__(self: Self) -> Awaitable[Self]: ... def __aexit__( self, __exc_type: Optional[Type[BaseException]], diff --git a/dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch b/dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch index ed544d8..65a3e35 100644 --- a/dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch +++ b/dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch @@ -1,13 +1,13 @@ ---- ../contextlib.pyi 2021-06-29 19:05:46.515307191 +0100 -+++ contextlib2/__init__.pyi 2021-06-29 19:15:26.814620184 +0100 +--- ../contextlib.pyi 2021-07-16 08:26:16.409945194 +0100 ++++ contextlib2/__init__.pyi 2021-07-16 08:32:00.363150171 +0100 @@ -1,3 +1,6 @@ +# Type hints copied from the typeshed project under the Apache License 2.0 +# https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE + import sys + from _typeshed import Self from types import TracebackType - from typing import ( -@@ -16,8 +19,14 @@ +@@ -17,8 +20,14 @@ ) from typing_extensions import ParamSpec, Protocol @@ -23,7 +23,7 @@ AbstractAsyncContextManager = AsyncContextManager _T = TypeVar("_T") -@@ -35,7 +44,7 @@ +@@ -36,7 +45,7 @@ # type ignore to deal with incomplete ParamSpec support in mypy def contextmanager(func: Callable[_P, Iterator[_T]]) -> Callable[_P, _GeneratorContextManager[_T]]: ... # type: ignore @@ -32,7 +32,7 @@ def asynccontextmanager(func: Callable[_P, AsyncIterator[_T]]) -> Callable[_P, AsyncContextManager[_T]]: ... # type: ignore class _SupportsClose(Protocol): -@@ -46,7 +55,7 @@ +@@ -47,7 +56,7 @@ class closing(ContextManager[_SupportsCloseT]): def __init__(self, thing: _SupportsCloseT) -> None: ... @@ -41,16 +41,16 @@ class _SupportsAclose(Protocol): def aclose(self) -> Awaitable[object]: ... _SupportsAcloseT = TypeVar("_SupportsAcloseT", bound=_SupportsAclose) -@@ -88,7 +97,7 @@ +@@ -87,7 +96,7 @@ __traceback: Optional[TracebackType], ) -> bool: ... -if sys.version_info >= (3, 7): +if True: - _S = TypeVar("_S", bound=AsyncExitStack) - _ExitCoroFunc = Callable[[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]], Awaitable[bool]] -@@ -112,7 +121,8 @@ + _CallbackCoroFunc = Callable[..., Awaitable[Any]] + _ACM_EF = TypeVar("_ACM_EF", AsyncContextManager[Any], _ExitCoroFunc) +@@ -109,7 +118,8 @@ __traceback: Optional[TracebackType], ) -> Awaitable[bool]: ... @@ -60,7 +60,7 @@ class nullcontext(AbstractContextManager[_T], AbstractAsyncContextManager[_T]): enter_result: _T @overload -@@ -123,13 +133,3 @@ +@@ -120,13 +130,3 @@ def __exit__(self, *exctype: Any) -> None: ... async def __aenter__(self) -> _T: ... async def __aexit__(self, *exctype: Any) -> None: ... From a35252eefd32a039ad726db4a1965db74e08ee27 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 20 Jul 2021 14:11:05 +0100 Subject: [PATCH 2/4] backport _typeshed.Self --- contextlib2/__init__.pyi | 2 +- contextlib2/_typeshed.py | 5 +++++ dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch | 9 ++++++--- 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 contextlib2/_typeshed.py diff --git a/contextlib2/__init__.pyi b/contextlib2/__init__.pyi index 4549200..30ab561 100644 --- a/contextlib2/__init__.pyi +++ b/contextlib2/__init__.pyi @@ -2,7 +2,7 @@ # https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE import sys -from _typeshed import Self +from ._typeshed import Self from types import TracebackType from typing import ( IO, diff --git a/contextlib2/_typeshed.py b/contextlib2/_typeshed.py new file mode 100644 index 0000000..f05558d --- /dev/null +++ b/contextlib2/_typeshed.py @@ -0,0 +1,5 @@ +from typing import TypeVar + +# Use for "self" annotations: +# def __enter__(self: Self) -> Self: ... +Self = TypeVar("Self") diff --git a/dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch b/dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch index 65a3e35..31d9882 100644 --- a/dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch +++ b/dev/py3_10_contextlib_pyi_to_contextlib2_pyi.patch @@ -1,12 +1,15 @@ --- ../contextlib.pyi 2021-07-16 08:26:16.409945194 +0100 -+++ contextlib2/__init__.pyi 2021-07-16 08:32:00.363150171 +0100 -@@ -1,3 +1,6 @@ ++++ contextlib2/__init__.pyi 2021-07-20 14:10:49.571136279 +0100 +@@ -1,5 +1,8 @@ +# Type hints copied from the typeshed project under the Apache License 2.0 +# https://github.com/python/typeshed/blob/64c85cdd449ccaff90b546676220c9ecfa6e697f/LICENSE + import sys - from _typeshed import Self +-from _typeshed import Self ++from ._typeshed import Self from types import TracebackType + from typing import ( + IO, @@ -17,8 +20,14 @@ ) from typing_extensions import ParamSpec, Protocol From d78420a8081b4de6f49dd8bebde3000f58bc18c0 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 20 Jul 2021 17:38:32 +0100 Subject: [PATCH 3/4] Update contextlib2/_typeshed.py --- contextlib2/_typeshed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contextlib2/_typeshed.py b/contextlib2/_typeshed.py index f05558d..80cdf3d 100644 --- a/contextlib2/_typeshed.py +++ b/contextlib2/_typeshed.py @@ -2,4 +2,4 @@ from typing import TypeVar # Use for "self" annotations: # def __enter__(self: Self) -> Self: ... -Self = TypeVar("Self") +Self = TypeVar("Self") # pragma: no cover From 3d2540dda14a125f51225af8df6c9dd811e1b0fd Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Tue, 20 Jul 2021 17:38:40 +0100 Subject: [PATCH 4/4] Update contextlib2/_typeshed.py --- contextlib2/_typeshed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contextlib2/_typeshed.py b/contextlib2/_typeshed.py index 80cdf3d..9e065ba 100644 --- a/contextlib2/_typeshed.py +++ b/contextlib2/_typeshed.py @@ -1,4 +1,4 @@ -from typing import TypeVar +from typing import TypeVar # pragma: no cover # Use for "self" annotations: # def __enter__(self: Self) -> Self: ...