Skip to content

Commit b23159e

Browse files
gh-89696: Fix loop.sock_connect docs on address resolution
The docs claimed unconditionally that the address no longer needs to be resolved, but only SelectorEventLoop does that. ProactorEventLoop, the default event loop on Windows, passes the address straight to ConnectEx() and WSAConnect(), which parse it with WSAStringToAddress() and therefore only accept numeric addresses.
1 parent adebb68 commit b23159e

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

Doc/library/asyncio-eventloop.rst

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,12 +1145,21 @@ convenient.
11451145

11461146
*sock* must be a non-blocking socket.
11471147

1148+
With :class:`SelectorEventLoop`, *address* does not need to be resolved:
1149+
for :const:`~socket.AF_INET` and :const:`~socket.AF_INET6` sockets,
1150+
``sock_connect`` first checks whether *address* is already resolved by
1151+
calling :func:`socket.inet_pton`, and uses :meth:`loop.getaddrinfo` to
1152+
resolve it if it is not.
1153+
1154+
:class:`ProactorEventLoop`, the default event loop on Windows, does not
1155+
resolve *address*. The host must already be a numeric IP address; passing
1156+
a host name raises :exc:`OSError`. Resolve the address with
1157+
:meth:`loop.getaddrinfo` first, or use :meth:`loop.create_connection`,
1158+
which resolves the address on every platform.
1159+
11481160
.. versionchanged:: 3.5.2
1149-
``address`` no longer needs to be resolved. ``sock_connect``
1150-
will try to check if the *address* is already resolved by calling
1151-
:func:`socket.inet_pton`. If not,
1152-
:meth:`loop.getaddrinfo` will be used to resolve the
1153-
*address*.
1161+
With :class:`SelectorEventLoop`, ``address`` no longer needs to be
1162+
resolved.
11541163

11551164
.. seealso::
11561165

0 commit comments

Comments
 (0)