From 73cb1fa0576808d70d7dc21bc04359f819253c91 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Thu, 20 Jan 2022 15:13:45 +0000 Subject: [PATCH 01/11] refine asyncio call_exception_handler context type --- stdlib/asyncio/base_events.pyi | 17 ++++++++++++++--- stdlib/asyncio/events.pyi | 17 ++++++++++++++--- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index b4b111698ea8..9cbfe582f5b3 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -9,15 +9,26 @@ from asyncio.tasks import Task from asyncio.transports import BaseTransport from collections.abc import Iterable from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket -from typing import IO, Any, Awaitable, Callable, Generator, Sequence, TypeVar, Union, overload -from typing_extensions import Literal +from typing import IO, Any, AsyncGenerator, Awaitable, Callable, Generator, Sequence, TypeVar, Union, overload +from typing_extensions import Literal, NotRequired, TypedDict if sys.version_info >= (3, 7): from contextvars import Context _T = TypeVar("_T") _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) -_Context = dict[str, Any] + +class _Context(TypedDict): + message: str + exception: NotRequired[BaseException] + future: NotRequired[Future[Any]] + task: NotRequired[Task[Any]] + handle: NotRequired[Handle] + protocol: NotRequired[BaseProtocol] + transport: NotRequired[BaseTransport] + socket: NotRequired[socket] + asyncgen: NotRequired[AsyncGenerator[Any, Any]] + _ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any] _ProtocolFactory = Callable[[], BaseProtocol] _SSLContext = Union[bool, None, ssl.SSLContext] diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index a2b6b8a77fc9..57583196a16f 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -3,8 +3,8 @@ import sys 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, Generator, Sequence, TypeVar, Union, overload -from typing_extensions import Literal +from typing import IO, Any, AsyncGenerator, Awaitable, Callable, Generator, Sequence, TypeVar, Union, overload +from typing_extensions import Literal, NotRequired, TypedDict from .base_events import Server from .futures import Future @@ -18,7 +18,18 @@ if sys.version_info >= (3, 7): _T = TypeVar("_T") _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) -_Context = dict[str, Any] + +class _Context(TypedDict): + message: str + exception: NotRequired[BaseException] + future: NotRequired[Future[Any]] + task: NotRequired[Task[Any]] + handle: NotRequired[Handle] + protocol: NotRequired[BaseProtocol] + transport: NotRequired[BaseTransport] + socket: NotRequired[socket] + asyncgen: NotRequired[AsyncGenerator[Any, Any]] + _ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any] _ProtocolFactory = Callable[[], BaseProtocol] _SSLContext = Union[bool, None, ssl.SSLContext] From 07a870873392e9b4215d8a0d6afcbb8c8643835f Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 11 Feb 2022 17:49:36 -0800 Subject: [PATCH 02/11] Update stdlib/asyncio/base_events.pyi --- stdlib/asyncio/base_events.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 7f07b00f3431..9e782107b78f 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -17,9 +17,9 @@ if sys.version_info >= (3, 7): _T = TypeVar("_T") _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) - -class _Context(TypedDict): +class _BaseContext(TypedDict): message: str +class _Context(_BaseContext, total=False): exception: NotRequired[BaseException] future: NotRequired[Future[Any]] task: NotRequired[Task[Any]] From ef514d65aee1ef9ae8848ed6c0898d802b63af1e Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 11 Feb 2022 17:49:41 -0800 Subject: [PATCH 03/11] Update stdlib/asyncio/base_events.pyi --- stdlib/asyncio/base_events.pyi | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 9e782107b78f..41200147a50f 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -20,14 +20,14 @@ _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) class _BaseContext(TypedDict): message: str class _Context(_BaseContext, total=False): - exception: NotRequired[BaseException] - future: NotRequired[Future[Any]] - task: NotRequired[Task[Any]] - handle: NotRequired[Handle] - protocol: NotRequired[BaseProtocol] - transport: NotRequired[BaseTransport] - socket: NotRequired[socket] - asyncgen: NotRequired[AsyncGenerator[Any, Any]] + exception: BaseException + future: Future[Any] + task: Task[Any] + handle: Handle + protocol: BaseProtocol + transport: BaseTransport + socket: socket + asyncgen: AsyncGenerator[Any, Any] _ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any] _ProtocolFactory = Callable[[], BaseProtocol] From 63636ecd34f01dfbaa05f36c534b1848a68d37d5 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 11 Feb 2022 17:49:46 -0800 Subject: [PATCH 04/11] Update stdlib/asyncio/events.pyi --- 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 50afa86f7df6..550406541b3e 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -6,7 +6,7 @@ from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, Awaitable, Callable, Coroutine, Generator, Sequence, TypeVar, Union, overload from typing_extensions import Literal, NotRequired, TypedDict -from .base_events import Server +from .base_events import Server, _Context from .futures import Future from .protocols import BaseProtocol from .tasks import Task From c9ecc07249523ae05d8e255db61b471f4bf660c0 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 11 Feb 2022 17:49:50 -0800 Subject: [PATCH 05/11] Update stdlib/asyncio/events.pyi --- stdlib/asyncio/events.pyi | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 550406541b3e..bf90851f6c1d 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -18,18 +18,6 @@ if sys.version_info >= (3, 7): _T = TypeVar("_T") _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) - -class _Context(TypedDict): - message: str - exception: NotRequired[BaseException] - future: NotRequired[Future[Any]] - task: NotRequired[Task[Any]] - handle: NotRequired[Handle] - protocol: NotRequired[BaseProtocol] - transport: NotRequired[BaseTransport] - socket: NotRequired[socket] - asyncgen: NotRequired[AsyncGenerator[Any, Any]] - _ExceptionHandler = Callable[[AbstractEventLoop, _Context], Any] _ProtocolFactory = Callable[[], BaseProtocol] _SSLContext = Union[bool, None, ssl.SSLContext] From 923cc2f4ce1502ad4acb5f838becf2ad4ccab31e Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 11 Feb 2022 17:49:54 -0800 Subject: [PATCH 06/11] Update stdlib/asyncio/events.pyi --- 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 bf90851f6c1d..f4474bfbefdd 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -4,7 +4,7 @@ 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, Coroutine, Generator, Sequence, TypeVar, Union, overload -from typing_extensions import Literal, NotRequired, TypedDict +from typing_extensions import Literal, TypedDict from .base_events import Server, _Context from .futures import Future From eba70dae8433eb4d1744283b92f34728f140a247 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 11 Feb 2022 17:49:58 -0800 Subject: [PATCH 07/11] Update stdlib/asyncio/base_events.pyi --- stdlib/asyncio/base_events.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 41200147a50f..516ebb09a8db 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -10,7 +10,7 @@ from asyncio.transports import BaseTransport, ReadTransport, SubprocessTransport from collections.abc import Iterable from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, AsyncGenerator, Awaitable, Callable, Coroutine, Generator, Sequence, TypeVar, Union, overload -from typing_extensions import Literal, NotRequired, TypedDict +from typing_extensions import Literal, TypedDict if sys.version_info >= (3, 7): from contextvars import Context From 6d0b0fd5ad1758eda1c63ba131737ae3e9ae6f80 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sat, 12 Feb 2022 01:50:49 +0000 Subject: [PATCH 08/11] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/asyncio/base_events.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 516ebb09a8db..a724b773fbae 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -17,8 +17,10 @@ if sys.version_info >= (3, 7): _T = TypeVar("_T") _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) + class _BaseContext(TypedDict): message: str + class _Context(_BaseContext, total=False): exception: BaseException future: Future[Any] From 9be3e73bafbc3c40e210d487ce5a8328367c3c31 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 11 Feb 2022 17:57:23 -0800 Subject: [PATCH 09/11] Update stdlib/asyncio/events.pyi --- 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 f4474bfbefdd..a65a7a7babe0 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -4,7 +4,7 @@ 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, Coroutine, Generator, Sequence, TypeVar, Union, overload -from typing_extensions import Literal, TypedDict +from typing_extensions import Literal from .base_events import Server, _Context from .futures import Future From 5fe10e9f6146e54ef8a6d6523bc47a52b9bf2a9e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 18 Apr 2022 18:30:59 +0000 Subject: [PATCH 10/11] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/asyncio/base_events.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index e6199f410b8e..2efe78d3e79a 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -6,7 +6,7 @@ from asyncio.futures import Future from asyncio.protocols import BaseProtocol from asyncio.tasks import Task from asyncio.transports import BaseTransport, ReadTransport, SubprocessTransport, WriteTransport -from collections.abc import Awaitable, AsyncGenerator, Callable, Coroutine, Generator, Iterable, Sequence +from collections.abc import AsyncGenerator, Awaitable, Callable, Coroutine, Generator, Iterable, Sequence from socket import AddressFamily, SocketKind, _Address, _RetAddress, socket from typing import IO, Any, TypeVar, overload from typing_extensions import Literal, TypeAlias, TypedDict From f17ee70bb618d5d99e97240c82e9f3d8d4ab4e1b Mon Sep 17 00:00:00 2001 From: AlexWaygood Date: Mon, 18 Apr 2022 19:35:26 +0100 Subject: [PATCH 11/11] Fix bad merge --- stdlib/asyncio/events.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index 88735f311fd8..a679bc9dbfbc 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -78,6 +78,7 @@ _T = TypeVar("_T") _ProtocolT = TypeVar("_ProtocolT", bound=BaseProtocol) _ExceptionHandler: TypeAlias = Callable[[AbstractEventLoop, _Context], Any] _ProtocolFactory: TypeAlias = Callable[[], BaseProtocol] +_SSLContext: TypeAlias = bool | None | ssl.SSLContext class Handle: _cancelled: bool