From a69ecc681460d5a0b43312667f0c302ca41f8793 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 27 Dec 2025 15:53:18 -0600 Subject: [PATCH 1/2] improve datagram received type --- stdlib/asyncio/protocols.pyi | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/stdlib/asyncio/protocols.pyi b/stdlib/asyncio/protocols.pyi index 3a8965f03e29..db1ce8e79f76 100644 --- a/stdlib/asyncio/protocols.pyi +++ b/stdlib/asyncio/protocols.pyi @@ -1,6 +1,5 @@ from _typeshed import ReadableBuffer from asyncio import transports -from typing import Any # Keep asyncio.__all__ updated with any changes to __all__ here __all__ = ("BaseProtocol", "Protocol", "DatagramProtocol", "SubprocessProtocol", "BufferedProtocol") @@ -27,11 +26,9 @@ class BufferedProtocol(BaseProtocol): class DatagramProtocol(BaseProtocol): __slots__ = () def connection_made(self, transport: transports.DatagramTransport) -> None: ... # type: ignore[override] - # addr can be a tuple[int, int] for some unusual protocols like socket.AF_NETLINK. - # Use tuple[str | Any, int] to not cause typechecking issues on most usual cases. - # This could be improved by using tuple[AnyOf[str, int], int] if the AnyOf feature is accepted. - # See https://github.com/python/typing/issues/566 - def datagram_received(self, data: bytes, addr: tuple[str | Any, int]) -> None: ... + # Address is a 2-tuple (host, port) for IPv4, 4-tuple (host, port, flowinfo, scope_id) for IPv6, + # or tuple[int, int] for some unusual protocols like socket.AF_NETLINK. + def datagram_received(self, data: bytes, addr: tuple[str, int] | tuple[str, int, int, int] | tuple[int, int]) -> None: ... def error_received(self, exc: Exception) -> None: ... class SubprocessProtocol(BaseProtocol): From 51c7a2ba0cc07193a4d93729fd13bf2039251822 Mon Sep 17 00:00:00 2001 From: Max Muoto Date: Sat, 27 Dec 2025 15:57:37 -0600 Subject: [PATCH 2/2] simplify --- stdlib/asyncio/protocols.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/asyncio/protocols.pyi b/stdlib/asyncio/protocols.pyi index db1ce8e79f76..6be0caed84f6 100644 --- a/stdlib/asyncio/protocols.pyi +++ b/stdlib/asyncio/protocols.pyi @@ -28,7 +28,7 @@ class DatagramProtocol(BaseProtocol): def connection_made(self, transport: transports.DatagramTransport) -> None: ... # type: ignore[override] # Address is a 2-tuple (host, port) for IPv4, 4-tuple (host, port, flowinfo, scope_id) for IPv6, # or tuple[int, int] for some unusual protocols like socket.AF_NETLINK. - def datagram_received(self, data: bytes, addr: tuple[str, int] | tuple[str, int, int, int] | tuple[int, int]) -> None: ... + def datagram_received(self, data: bytes, addr: tuple[str | int, int] | tuple[str, int, int, int]) -> None: ... def error_received(self, exc: Exception) -> None: ... class SubprocessProtocol(BaseProtocol):