Skip to content

Commit 60be8e9

Browse files
committed
[asyncio] Support IPv6 addr type in DatagramProtocol.datagram_received
When using IPv6, the `addr` parameter passed to `datagram_received` is a 4-tuple `(host, port, flowinfo, scope_id)` of type `tuple[str, int, int, int]`, not a 2-tuple. Add this case to the union type so IPv6 datagram protocols can be properly typed without resorting to `Any`. Fixes #15169
1 parent 81a6d24 commit 60be8e9

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

stdlib/asyncio/protocols.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class DatagramProtocol(BaseProtocol):
3131
# Use tuple[str | Any, int] to not cause typechecking issues on most usual cases.
3232
# This could be improved by using tuple[AnyOf[str, int], int] if the AnyOf feature is accepted.
3333
# See https://github.com/python/typing/issues/566
34-
def datagram_received(self, data: bytes, addr: tuple[str | Any, int]) -> None: ...
34+
# For IPv6, addr is a 4-tuple: (host, port, flowinfo, scope_id).
35+
def datagram_received(self, data: bytes, addr: tuple[str | Any, int] | tuple[str, int, int, int]) -> None: ...
3536
def error_received(self, exc: Exception) -> None: ...
3637

3738
class SubprocessProtocol(BaseProtocol):

0 commit comments

Comments
 (0)