diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index 7bb50f7b8aa47e2..a6142cf34844dab 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -12,6 +12,7 @@ import errno import fractions import gc +import inspect import io import itertools import math @@ -945,6 +946,14 @@ def requireSocket(*args): class GeneralModuleTests(unittest.TestCase): + @unittest.skipUnless(hasattr(socket.socket, "sendmsg"), + "sendmsg not supported") + def test_sendmsg_signature(self): + self.assertEqual( + str(inspect.signature(socket.socket.sendmsg)), + "(self, buffers, ancdata=(), flags=0, address=None, /)", + ) + @unittest.skipUnless(_socket is not None, 'need _socket module') def test_socket_type(self): self.assertTrue(gc.is_tracked(_socket.socket)) diff --git a/Misc/NEWS.d/next/Library/2026-08-12-20-51-27.gh-issue-155621.h9V1sW.rst b/Misc/NEWS.d/next/Library/2026-08-12-20-51-27.gh-issue-155621.h9V1sW.rst new file mode 100644 index 000000000000000..78a1a681276fc84 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-12-20-51-27.gh-issue-155621.h9V1sW.rst @@ -0,0 +1,3 @@ +Fix the signature of :meth:`socket.socket.sendmsg` to expose the *ancdata* +and *address* defaults as ``()`` and ``None`` instead of +````. diff --git a/Modules/clinic/socketmodule.c.h b/Modules/clinic/socketmodule.c.h index b565e7516d50f33..aeed9e96435b93b 100644 --- a/Modules/clinic/socketmodule.c.h +++ b/Modules/clinic/socketmodule.c.h @@ -130,8 +130,7 @@ _socket_socket_sendall(PyObject *s, PyObject *const *args, Py_ssize_t nargs) #if defined(CMSG_LEN) PyDoc_STRVAR(_socket_socket_sendmsg__doc__, -"sendmsg($self, buffers, ancdata=, flags=0,\n" -" address=, /)\n" +"sendmsg($self, buffers, ancdata=(), flags=0, address=None, /)\n" "--\n" "\n" "Send normal and ancillary data to the socket.\n" @@ -543,4 +542,4 @@ _socket_if_indextoname(PyObject *module, PyObject *arg) #ifndef _SOCKET_IF_INDEXTONAME_METHODDEF #define _SOCKET_IF_INDEXTONAME_METHODDEF #endif /* !defined(_SOCKET_IF_INDEXTONAME_METHODDEF) */ -/*[clinic end generated code: output=0b1fa78ac6589353 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=116cf1cf631becf2 input=a9049054013a1b77]*/ diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index f9c77c631b5d2af..cd096ccb08198ba 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -4929,9 +4929,9 @@ sock_sendmsg_impl(PySocketSockObject *s, void *data) _socket.socket.sendmsg self as s: self(type="PySocketSockObject *") buffers as data_arg: object - ancdata as cmsg_arg: object = NULL + ancdata as cmsg_arg: object(c_default="NULL") = () flags: int = 0 - address as addr_arg: object = NULL + address as addr_arg: object(c_default="NULL") = None / Send normal and ancillary data to the socket. @@ -4955,7 +4955,7 @@ static PyObject * _socket_socket_sendmsg_impl(PySocketSockObject *s, PyObject *data_arg, PyObject *cmsg_arg, int flags, PyObject *addr_arg) -/*[clinic end generated code: output=3b4cb1110644ce39 input=8ae408971a3aa329]*/ +/*[clinic end generated code: output=3b4cb1110644ce39 input=5fdf9b49bed3848b]*/ { Py_ssize_t i, ndatabufs = 0, ncmsgs, ncmsgbufs = 0;