Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions stdlib/@tests/test_cases/asyncio/check_protocols.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from __future__ import annotations

from asyncio import DatagramProtocol


class IPv4Protocol(DatagramProtocol):
def datagram_received(self, data: bytes, addr: tuple[str, int]) -> None: ...


class IPv6Protocol(DatagramProtocol):
def datagram_received(self, data: bytes, addr: tuple[str, int, int, int]) -> None: ...


class NetlinkProtocol(DatagramProtocol):
def datagram_received(self, data: bytes, addr: tuple[int, int]) -> None: ...
10 changes: 6 additions & 4 deletions stdlib/asyncio/protocols.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from _typeshed import ReadableBuffer
from asyncio import transports
from typing import Any
from typing_extensions import Unpack

# Keep asyncio.__all__ updated with any changes to __all__ here
__all__ = ("BaseProtocol", "Protocol", "DatagramProtocol", "SubprocessProtocol", "BufferedProtocol")
Expand All @@ -27,11 +28,12 @@ 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.
# addr can be a tuple[int, int] for some unusual protocols like socket.AF_NETLINK and
# a 4-tuple (host, port, flowinfo, scope_id) for IPv6,
# Use tuple[Any, int, Unpack[tuple[Any, ...]]] to not cause typechecking issues on most usual cases.
# This could be improved by using tuple[AnyOf[str, int], int, Unpack[tuple[Any, ...]]] 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 datagram_received(self, data: bytes, addr: tuple[Any, int, Unpack[tuple[Any, ...]]]) -> None: ...
def error_received(self, exc: Exception) -> None: ...

class SubprocessProtocol(BaseProtocol):
Expand Down
Loading