diff --git a/Lib/asyncio/selector_events.py b/Lib/asyncio/selector_events.py index f94bf10b4225e7..b2866d1e6aeb75 100644 --- a/Lib/asyncio/selector_events.py +++ b/Lib/asyncio/selector_events.py @@ -618,7 +618,7 @@ def _sock_sendto(self, fut, sock, data, address): else: fut.set_result(n) - async def sock_connect(self, sock, address): + async def sock_connect(self, sock, address, proto_addr_info=None): """Connect to a remote socket at address. This method is a coroutine. @@ -629,8 +629,9 @@ async def sock_connect(self, sock, address): if sock.family == socket.AF_INET or ( base_events._HAS_IPv6 and sock.family == socket.AF_INET6): + proto = proto_addr_info if proto_addr_info is not None else sock.proto resolved = await self._ensure_resolved( - address, family=sock.family, type=sock.type, proto=sock.proto, + address, family=sock.family, type=sock.type, proto=proto, loop=self, ) _, _, _, _, address = resolved[0] diff --git a/Misc/NEWS.d/next/Library/2024-08-20-12-51-58.gh-issue-123174.nXCVYU.rst b/Misc/NEWS.d/next/Library/2024-08-20-12-51-58.gh-issue-123174.nXCVYU.rst new file mode 100644 index 00000000000000..91ea137f78893c --- /dev/null +++ b/Misc/NEWS.d/next/Library/2024-08-20-12-51-58.gh-issue-123174.nXCVYU.rst @@ -0,0 +1,2 @@ +Allow the selection of the protocol used by getaddrinfo by adding an additional, optional parameter proto_addr_info +If not specified, use the protocol used by the socket (= previous behaviour)