From 56590f820e94987edf532f7b47772452a25d9c8f Mon Sep 17 00:00:00 2001 From: David Lechner Date: Fri, 6 Feb 2026 02:51:19 -0600 Subject: [PATCH] gh-144493: Improve error message in _overlapped.BindLocal() (#144495) Replace a confusing error message with one that actually explains what the error is in `_overlapped.BindLocal()`. Fixes: https://github.com/python/cpython/issues/144493 --- .../next/Library/2026-02-05-17-15-31.gh-issue-144493.XuxwVu.rst | 1 + Modules/overlapped.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Library/2026-02-05-17-15-31.gh-issue-144493.XuxwVu.rst diff --git a/Misc/NEWS.d/next/Library/2026-02-05-17-15-31.gh-issue-144493.XuxwVu.rst b/Misc/NEWS.d/next/Library/2026-02-05-17-15-31.gh-issue-144493.XuxwVu.rst new file mode 100644 index 00000000000..fe205b58013 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-02-05-17-15-31.gh-issue-144493.XuxwVu.rst @@ -0,0 +1 @@ +Improve an exception error message in ``_overlapped.BindLocal()`` that is raised when :meth:`asyncio.loop.sock_connect` is called on a :class:`asyncio.ProactorEventLoop` with a socket that has an invalid address family. diff --git a/Modules/overlapped.c b/Modules/overlapped.c index 09b57ce4b97..8c3575ff567 100644 --- a/Modules/overlapped.c +++ b/Modules/overlapped.c @@ -559,7 +559,7 @@ _overlapped_BindLocal_impl(PyObject *module, HANDLE Socket, int Family) ret = bind((SOCKET)Socket, (SOCKADDR*)&addr, sizeof(addr)) != SOCKET_ERROR; } else { - PyErr_SetString(PyExc_ValueError, "expected tuple of length 2 or 4"); + PyErr_SetString(PyExc_ValueError, "Only AF_INET and AF_INET6 families are supported"); return NULL; }