From 09a1932e681d4cc083b63e510f74d5ca8fafd2ad Mon Sep 17 00:00:00 2001 From: Thomas Cellerier Date: Wed, 23 Feb 2022 12:09:26 +0100 Subject: [PATCH] Address parameter of datagram_received can be of type tuple[int, int] (#7366) --- stdlib/asyncio/protocols.pyi | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stdlib/asyncio/protocols.pyi b/stdlib/asyncio/protocols.pyi index caae5d865..7b5169702 100644 --- a/stdlib/asyncio/protocols.pyi +++ b/stdlib/asyncio/protocols.pyi @@ -1,5 +1,6 @@ import sys from asyncio import transports +from typing import Any if sys.version_info >= (3, 7): __all__ = ("BaseProtocol", "Protocol", "DatagramProtocol", "SubprocessProtocol", "BufferedProtocol") @@ -24,7 +25,11 @@ if sys.version_info >= (3, 7): class DatagramProtocol(BaseProtocol): def connection_made(self, transport: transports.DatagramTransport) -> None: ... # type: ignore[override] - def datagram_received(self, data: bytes, addr: tuple[str, int]) -> None: ... + # 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: ... def error_received(self, exc: Exception) -> None: ... class SubprocessProtocol(BaseProtocol):