From 3d23f31ad51094cbbbf25d1c21f908f066dace2e Mon Sep 17 00:00:00 2001 From: lipengyu Date: Wed, 12 Aug 2026 20:35:00 +0800 Subject: [PATCH 1/3] Fix unrepresentable defaults in socket.sendmsg() signature --- Lib/test/test_socket.py | 9 +++++++++ .../2026-08-12-20-51-27.gh-issue-155621.h9V1sW.rst | 3 +++ Modules/clinic/socketmodule.c.h | 5 ++--- Modules/socketmodule.c | 6 +++--- 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2026-08-12-20-51-27.gh-issue-155621.h9V1sW.rst diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index e4b3d848923f8c9..bb7aa530473d5fd 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 00e5fb4cde3aefd..f89b91b9b997532 100644 --- a/Modules/clinic/socketmodule.c.h +++ b/Modules/clinic/socketmodule.c.h @@ -1018,8 +1018,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" @@ -2479,4 +2478,4 @@ _socket_CMSG_SPACE(PyObject *module, PyObject *arg) #ifndef _SOCKET_CMSG_SPACE_METHODDEF #define _SOCKET_CMSG_SPACE_METHODDEF #endif /* !defined(_SOCKET_CMSG_SPACE_METHODDEF) */ -/*[clinic end generated code: output=133662a8c304b1b7 input=a9049054013a1b77]*/ +/*[clinic end generated code: output=acc30d6fdeb54e90 input=a9049054013a1b77]*/ diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 9051420179aea11..70d3738b176cda2 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -4990,9 +4990,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. @@ -5016,7 +5016,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; From 3da62af2266ac99f300685767460d30cea6a4dfe Mon Sep 17 00:00:00 2001 From: lipengyu Date: Fri, 14 Aug 2026 22:31:48 +0800 Subject: [PATCH 2/3] address review --- Lib/test/test_socket.py | 9 --------- .../2026-08-12-20-51-27.gh-issue-155621.h9V1sW.rst | 3 --- 2 files changed, 12 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2026-08-12-20-51-27.gh-issue-155621.h9V1sW.rst diff --git a/Lib/test/test_socket.py b/Lib/test/test_socket.py index bb7aa530473d5fd..e4b3d848923f8c9 100644 --- a/Lib/test/test_socket.py +++ b/Lib/test/test_socket.py @@ -12,7 +12,6 @@ import errno import fractions import gc -import inspect import io import itertools import math @@ -946,14 +945,6 @@ 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 deleted file mode 100644 index 78a1a681276fc84..000000000000000 --- a/Misc/NEWS.d/next/Library/2026-08-12-20-51-27.gh-issue-155621.h9V1sW.rst +++ /dev/null @@ -1,3 +0,0 @@ -Fix the signature of :meth:`socket.socket.sendmsg` to expose the *ancdata* -and *address* defaults as ``()`` and ``None`` instead of -````. From 61d5b2420db3a3e062e6a2160aebab8d27900460 Mon Sep 17 00:00:00 2001 From: lipengyu Date: Fri, 14 Aug 2026 23:05:37 +0800 Subject: [PATCH 3/3] fix test failed --- Lib/test/test_inspect/test_inspect.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_inspect/test_inspect.py b/Lib/test/test_inspect/test_inspect.py index 76c346cd89eac04..ff7475447e95a03 100644 --- a/Lib/test/test_inspect/test_inspect.py +++ b/Lib/test/test_inspect/test_inspect.py @@ -6340,7 +6340,7 @@ def test_socket_module_has_signatures(self): # depends on the number of the arguments. methods_no_signature = {'ioctl', 'sendto', 'setsockopt'} # These have parameters with unrepresentable default values. - methods_unsupported_signature = {'listen', 'sendmsg', 'sendmsg_afalg'} + methods_unsupported_signature = {'listen', 'sendmsg_afalg'} defined = vars(socket.SocketType).keys() self._test_module_has_signatures(socket, no_signature, unsupported_signature,