From 73c266c5536bfc4e3cbe19f706de73d0451b7e84 Mon Sep 17 00:00:00 2001 From: gandalf3 Date: Fri, 20 Jan 2023 14:38:04 -0800 Subject: [PATCH 1/3] Add str to address arguments of asyncio.loop.create_datagram_endpoint Since python 3.7, asyncio.loop.create_datagram_endpoint expects the arguments `local_addr` and `remote_addr` to be `str` or `None` when the argument family=`socket.AF_UNIX` and the argument `sock` is `None` or also a unix socket. Here is a link to the relevant line in the standard library: https://github.com/python/cpython/blob/main/Lib/asyncio/base_events.py#L1319 And here is a link to the pull request for the change which introduced this in python 3.7: https://github.com/python/cpython/pull/3164 --- stdlib/asyncio/base_events.pyi | 19 ++++++++++++-- stdlib/asyncio/events.pyi | 47 +++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 17 deletions(-) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 6ff3c2c9f771..5c269f8a2cd7 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -342,8 +342,8 @@ class BaseEventLoop(AbstractEventLoop): async def create_datagram_endpoint( # type: ignore[override] self, protocol_factory: Callable[[], _ProtocolT], - local_addr: tuple[str, int] | None = None, - remote_addr: tuple[str, int] | None = None, + local_addr: tuple[str, int] | str | None = None, + remote_addr: tuple[str, int] | str | None = None, *, family: int = 0, proto: int = 0, @@ -352,6 +352,21 @@ class BaseEventLoop(AbstractEventLoop): allow_broadcast: bool | None = None, sock: socket | None = None, ) -> tuple[DatagramTransport, _ProtocolT]: ... + elif sys.version_info >= (3, 7): + async def create_datagram_endpoint( + self, + protocol_factory: Callable[[], _ProtocolT], + local_addr: tuple[str, int] | str | None = ..., + remote_addr: tuple[str, int] | str | None = ..., + *, + family: int = ..., + proto: int = ..., + flags: int = ..., + reuse_address: bool | None = ..., + reuse_port: bool | None = ..., + allow_broadcast: bool | None = ..., + sock: socket | None = ..., + ) -> tuple[DatagramTransport, _ProtocolT]: ... else: async def create_datagram_endpoint( self, diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index fd8213f55be7..efa95139672d 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -491,21 +491,38 @@ class AbstractEventLoop: async def sendfile( self, transport: WriteTransport, file: IO[bytes], offset: int = 0, count: int | None = None, *, fallback: bool = True ) -> int: ... - @abstractmethod - async def create_datagram_endpoint( - self, - protocol_factory: Callable[[], _ProtocolT], - local_addr: tuple[str, int] | None = None, - remote_addr: tuple[str, int] | None = None, - *, - family: int = 0, - proto: int = 0, - flags: int = 0, - reuse_address: bool | None = None, - reuse_port: bool | None = None, - allow_broadcast: bool | None = None, - sock: socket | None = None, - ) -> tuple[DatagramTransport, _ProtocolT]: ... + if sys.version_info >= (3, 7): + @abstractmethod + async def create_datagram_endpoint( + self, + protocol_factory: Callable[[], _ProtocolT], + local_addr: tuple[str, int] | str | None = None, + remote_addr: tuple[str, int] | str | None = None, + *, + family: int = 0, + proto: int = 0, + flags: int = 0, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + allow_broadcast: bool | None = None, + sock: socket | None = None, + ) -> tuple[DatagramTransport, _ProtocolT]: ... + else: + @abstractmethod + async def create_datagram_endpoint( + self, + protocol_factory: Callable[[], _ProtocolT], + local_addr: tuple[str, int] | None = None, + remote_addr: tuple[str, int] | None = None, + *, + family: int = 0, + proto: int = 0, + flags: int = 0, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + allow_broadcast: bool | None = None, + sock: socket | None = None, + ) -> tuple[DatagramTransport, _ProtocolT]: ... # Pipes and subprocesses. @abstractmethod async def connect_read_pipe( From 0611939809b43765a27900640aa0cd31d23415a3 Mon Sep 17 00:00:00 2001 From: gandalf3 Date: Sat, 21 Jan 2023 10:52:45 -0800 Subject: [PATCH 2/3] fixup! Add str to address arguments of asyncio.loop.create_datagram_endpoint --- stdlib/asyncio/base_events.pyi | 17 +---------------- stdlib/asyncio/events.pyi | 4 ++-- 2 files changed, 3 insertions(+), 18 deletions(-) diff --git a/stdlib/asyncio/base_events.pyi b/stdlib/asyncio/base_events.pyi index 5c269f8a2cd7..8af829d4f4a9 100644 --- a/stdlib/asyncio/base_events.pyi +++ b/stdlib/asyncio/base_events.pyi @@ -352,7 +352,7 @@ class BaseEventLoop(AbstractEventLoop): allow_broadcast: bool | None = None, sock: socket | None = None, ) -> tuple[DatagramTransport, _ProtocolT]: ... - elif sys.version_info >= (3, 7): + else: async def create_datagram_endpoint( self, protocol_factory: Callable[[], _ProtocolT], @@ -367,21 +367,6 @@ class BaseEventLoop(AbstractEventLoop): allow_broadcast: bool | None = ..., sock: socket | None = ..., ) -> tuple[DatagramTransport, _ProtocolT]: ... - else: - async def create_datagram_endpoint( - self, - protocol_factory: Callable[[], _ProtocolT], - local_addr: tuple[str, int] | None = ..., - remote_addr: tuple[str, int] | None = ..., - *, - family: int = ..., - proto: int = ..., - flags: int = ..., - reuse_address: bool | None = ..., - reuse_port: bool | None = ..., - allow_broadcast: bool | None = ..., - sock: socket | None = ..., - ) -> tuple[DatagramTransport, _ProtocolT]: ... # Pipes and subprocesses. async def connect_read_pipe( self, protocol_factory: Callable[[], _ProtocolT], pipe: Any diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index efa95139672d..e3924619f719 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -512,8 +512,8 @@ class AbstractEventLoop: async def create_datagram_endpoint( self, protocol_factory: Callable[[], _ProtocolT], - local_addr: tuple[str, int] | None = None, - remote_addr: tuple[str, int] | None = None, + local_addr: tuple[str, int] | str | None = None, + remote_addr: tuple[str, int] | str | None = None, *, family: int = 0, proto: int = 0, From f79fbda74c1bb39d37bb16b22d3ca73fd941d39b Mon Sep 17 00:00:00 2001 From: gandalf3 Date: Sat, 21 Jan 2023 11:01:14 -0800 Subject: [PATCH 3/3] fixup! fixup! Add str to address arguments of asyncio.loop.create_datagram_endpoint --- stdlib/asyncio/events.pyi | 47 +++++++++++++-------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/stdlib/asyncio/events.pyi b/stdlib/asyncio/events.pyi index e3924619f719..aa209828161e 100644 --- a/stdlib/asyncio/events.pyi +++ b/stdlib/asyncio/events.pyi @@ -491,38 +491,21 @@ class AbstractEventLoop: async def sendfile( self, transport: WriteTransport, file: IO[bytes], offset: int = 0, count: int | None = None, *, fallback: bool = True ) -> int: ... - if sys.version_info >= (3, 7): - @abstractmethod - async def create_datagram_endpoint( - self, - protocol_factory: Callable[[], _ProtocolT], - local_addr: tuple[str, int] | str | None = None, - remote_addr: tuple[str, int] | str | None = None, - *, - family: int = 0, - proto: int = 0, - flags: int = 0, - reuse_address: bool | None = None, - reuse_port: bool | None = None, - allow_broadcast: bool | None = None, - sock: socket | None = None, - ) -> tuple[DatagramTransport, _ProtocolT]: ... - else: - @abstractmethod - async def create_datagram_endpoint( - self, - protocol_factory: Callable[[], _ProtocolT], - local_addr: tuple[str, int] | str | None = None, - remote_addr: tuple[str, int] | str | None = None, - *, - family: int = 0, - proto: int = 0, - flags: int = 0, - reuse_address: bool | None = None, - reuse_port: bool | None = None, - allow_broadcast: bool | None = None, - sock: socket | None = None, - ) -> tuple[DatagramTransport, _ProtocolT]: ... + @abstractmethod + async def create_datagram_endpoint( + self, + protocol_factory: Callable[[], _ProtocolT], + local_addr: tuple[str, int] | str | None = None, + remote_addr: tuple[str, int] | str | None = None, + *, + family: int = 0, + proto: int = 0, + flags: int = 0, + reuse_address: bool | None = None, + reuse_port: bool | None = None, + allow_broadcast: bool | None = None, + sock: socket | None = None, + ) -> tuple[DatagramTransport, _ProtocolT]: ... # Pipes and subprocesses. @abstractmethod async def connect_read_pipe(