From d28e4da294323c6dd6c68079d16199254ed359b4 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 4 Jul 2021 10:56:04 +0300 Subject: [PATCH 1/4] use Self in contextlib.AsyncExitStack --- stdlib/contextlib.pyi | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index 72cd757e00bf..db5911f38ecc 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -90,8 +90,6 @@ class ExitStack(ContextManager[ExitStack]): ) -> bool: ... if sys.version_info >= (3, 7): - _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) @@ -103,9 +101,9 @@ if sys.version_info >= (3, 7): 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]], From 30b507f7f63b7967a1175365d1a8f2da1bd65c70 Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 4 Jul 2021 11:26:17 +0300 Subject: [PATCH 2/4] grepping for 'def __aenter__' --- stdlib/asyncio/events.pyi | 2 +- stubs/aiofiles/aiofiles/base.pyi | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 978bbea63716..6b7c629006be 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -57,7 +57,7 @@ class TimerHandle(Handle): class AbstractServer: def close(self) -> None: ... if sys.version_info >= (3, 7): - async def __aenter__(self: _T) -> _T: ... + async def __aenter__(self: Self) -> Self: ... async def __aexit__(self, *exc: Any) -> None: ... def get_loop(self) -> AbstractEventLoop: ... def is_serving(self) -> bool: ... diff --git a/stubs/aiofiles/aiofiles/base.pyi b/stubs/aiofiles/aiofiles/base.pyi index 0f5f99a2e467..b06adf68074a 100644 --- a/stubs/aiofiles/aiofiles/base.pyi +++ b/stubs/aiofiles/aiofiles/base.pyi @@ -1,3 +1,4 @@ +from _typeshed import Self from types import CodeType, FrameType, TracebackType, coroutine from typing import Any, Coroutine, Generator, Generic, Iterator, Optional, Type, TypeVar, Union @@ -8,7 +9,7 @@ _T_contra = TypeVar("_T_contra", contravariant=True) class AsyncBase(Generic[_T]): def __init__(self, file: str, loop: Any, executor: Any) -> None: ... - async def __aiter__(self) -> Iterator[_T]: ... + async def __aiter__(self: Self) -> Self: ... async def __anext__(self) -> _T: ... class AiofilesContextManager(Generic[_T_co, _T_contra, _V_co]): From 995cb0c13816ff4eaddfe5fb696f201492b0617f Mon Sep 17 00:00:00 2001 From: Akuli Date: Sun, 4 Jul 2021 11:27:22 +0300 Subject: [PATCH 3/4] fix --- stdlib/asyncio/events.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 6b7c629006be..61aecbf6a698 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -1,6 +1,6 @@ import ssl import sys -from _typeshed import FileDescriptorLike +from _typeshed import FileDescriptorLike, Self from abc import ABCMeta, abstractmethod from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, Awaitable, Callable, Dict, Generator, List, Optional, Sequence, Tuple, TypeVar, Union, overload From 676f8bea599d7d2de47d69303271b5773c9f41b6 Mon Sep 17 00:00:00 2001 From: Akuli Date: Mon, 5 Jul 2021 21:35:32 +0300 Subject: [PATCH 4/4] fix copy/pasta method --- stdlib/contextlib.pyi | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/stdlib/contextlib.pyi b/stdlib/contextlib.pyi index db5911f38ecc..e2a680e4c65e 100644 --- a/stdlib/contextlib.pyi +++ b/stdlib/contextlib.pyi @@ -72,14 +72,12 @@ 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: Self) -> Self: ... def __exit__(