Skip to content

gh-135748: Use Argument Clinic for more socket functions - #155257

Open
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:socket-clinic
Open

gh-135748: Use Argument Clinic for more socket functions#155257
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:socket-clinic

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 5, 2026

Copy link
Copy Markdown
Member

Convert all convertible functions and methods of the socket module to Argument Clinic. They now have signatures for introspection, and functions which take several arguments use METH_FASTCALL instead of METH_VARARGS.

The number of _socket callables for which inspect.signature() fails drops from 26 to 7. Five of those seven are deliberate: listen() (the default is Py_MIN(SOMAXCONN, 128)), getservbyname() and getservbyport() (the C default is NULL and None is not accepted), sendmsg() and sendmsg_afalg() (arguments which are absent rather than defaulted).

ioctl(), sendto() and setsockopt() are left as they are. Their behaviour depends on the number of the arguments or on the value of a preceding argument, which Argument Clinic cannot express:

  • sendto(data[, flags], address) -- the optional argument is in the middle, while optional groups only support [left] required [right].
  • setsockopt() distinguishes 3 from 4 arguments with PyTuple_Size(), and both resulting error messages are asserted by test_socket.
  • ioctl() parses its second argument differently depending on cmd.

The parameter names are taken from the existing docstrings. Seven of them differ from Doc/library/socket.rst (for example recv(buffersize) versus the documented bufsize); the documentation is left unchanged here.

Convert all convertible functions and methods of the socket module.
They now have signatures for introspection, and functions which take
several arguments use METH_FASTCALL instead of METH_VARARGS.

ioctl(), sendto() and setsockopt() are left as they are.  Their
behaviour depends on the number of the arguments or on the value of a
preceding argument, which Argument Clinic cannot express.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant