11from _typeshed import ReadableBuffer
22from asyncio import transports
3+ from typing import Any
4+ from typing_extensions import Unpack
35
46# Keep asyncio.__all__ updated with any changes to __all__ here
57__all__ = ("BaseProtocol" , "Protocol" , "DatagramProtocol" , "SubprocessProtocol" , "BufferedProtocol" )
@@ -26,9 +28,12 @@ class BufferedProtocol(BaseProtocol):
2628class DatagramProtocol (BaseProtocol ):
2729 __slots__ = ()
2830 def connection_made (self , transport : transports .DatagramTransport ) -> None : ... # type: ignore[override]
29- # Address is a 2-tuple (host, port) for IPv4, 4-tuple (host, port, flowinfo, scope_id) for IPv6,
30- # or tuple[int, int] for some unusual protocols like socket.AF_NETLINK.
31- def datagram_received (self , data : bytes , addr : tuple [str | int , int ] | tuple [str , int , int , int ]) -> None : ...
31+ # addr can be a tuple[int, int] for some unusual protocols like socket.AF_NETLINK and
32+ # a 4-tuple (host, port, flowinfo, scope_id) for IPv6,
33+ # Use tuple[str | Any, int] to not cause typechecking issues on most usual cases.
34+ # This could be improved by using tuple[AnyOf[str, int], int] if the AnyOf feature is accepted.
35+ # See https://github.com/python/typing/issues/566
36+ def datagram_received (self , data : bytes , addr : tuple [str | Any , int , Unpack [tuple [Any , ...]]]) -> None : ...
3237 def error_received (self , exc : Exception ) -> None : ...
3338
3439class SubprocessProtocol (BaseProtocol ):
0 commit comments