Skip to content

Commit 9f87800

Browse files
gh-135748: Use Argument Clinic for more socket functions (GH-155257)
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.
1 parent 8123ed1 commit 9f87800

7 files changed

Lines changed: 2822 additions & 768 deletions

File tree

‎Include/internal/pycore_global_objects_fini_generated.h‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Include/internal/pycore_global_strings.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ struct _Py_global_strings {
319319
STRUCT_FOR_ID(argv)
320320
STRUCT_FOR_ID(as_integer_ratio)
321321
STRUCT_FOR_ID(asend)
322+
STRUCT_FOR_ID(assoclen)
322323
STRUCT_FOR_ID(ast)
323324
STRUCT_FOR_ID(athrow)
324325
STRUCT_FOR_ID(attr)
@@ -534,6 +535,7 @@ struct _Py_global_strings {
534535
STRUCT_FOR_ID(headers)
535536
STRUCT_FOR_ID(hi)
536537
STRUCT_FOR_ID(hook)
538+
STRUCT_FOR_ID(host)
537539
STRUCT_FOR_ID(hour)
538540
STRUCT_FOR_ID(hours)
539541
STRUCT_FOR_ID(id)
@@ -582,6 +584,7 @@ struct _Py_global_strings {
582584
STRUCT_FOR_ID(iter)
583585
STRUCT_FOR_ID(iterable)
584586
STRUCT_FOR_ID(iterations)
587+
STRUCT_FOR_ID(iv)
585588
STRUCT_FOR_ID(join)
586589
STRUCT_FOR_ID(jump)
587590
STRUCT_FOR_ID(keepends)
@@ -660,6 +663,7 @@ struct _Py_global_strings {
660663
STRUCT_FOR_ID(namespace_separator)
661664
STRUCT_FOR_ID(namespaces)
662665
STRUCT_FOR_ID(native)
666+
STRUCT_FOR_ID(nbytes)
663667
STRUCT_FOR_ID(ndigits)
664668
STRUCT_FOR_ID(nested)
665669
STRUCT_FOR_ID(new_file_name)
@@ -684,6 +688,7 @@ struct _Py_global_strings {
684688
STRUCT_FOR_ID(onceregistry)
685689
STRUCT_FOR_ID(only_active_thread)
686690
STRUCT_FOR_ID(only_keys)
691+
STRUCT_FOR_ID(op)
687692
STRUCT_FOR_ID(oparg)
688693
STRUCT_FOR_ID(opcode)
689694
STRUCT_FOR_ID(opcodes)
@@ -718,6 +723,7 @@ struct _Py_global_strings {
718723
STRUCT_FOR_ID(pidfd)
719724
STRUCT_FOR_ID(pointer_bits)
720725
STRUCT_FOR_ID(policy)
726+
STRUCT_FOR_ID(port)
721727
STRUCT_FOR_ID(pos)
722728
STRUCT_FOR_ID(pos1)
723729
STRUCT_FOR_ID(pos2)

‎Include/internal/pycore_runtime_init_generated.h‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Include/internal/pycore_unicodeobject_generated.h‎

Lines changed: 24 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Lib/test/test_inspect/test_inspect.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6328,6 +6328,25 @@ def test_signal_module_has_signatures(self):
63286328
import signal
63296329
self._test_module_has_signatures(signal)
63306330

6331+
def test_socket_module_has_signatures(self):
6332+
import socket
6333+
# The socket type has no signature, it is created by socket().
6334+
no_signature = {'SocketType'}
6335+
# The C default is NULL and None is not accepted
6336+
unsupported_signature = {'getservbyname', 'getservbyport'}
6337+
# Not all functions and methods are available on all platforms.
6338+
unsupported_signature &= vars(socket).keys()
6339+
# These cannot be converted to Argument Clinic: their behaviour
6340+
# depends on the number of the arguments.
6341+
methods_no_signature = {'ioctl', 'sendto', 'setsockopt'}
6342+
# These have parameters with unrepresentable default values.
6343+
methods_unsupported_signature = {'listen', 'sendmsg', 'sendmsg_afalg'}
6344+
defined = vars(socket.SocketType).keys()
6345+
self._test_module_has_signatures(socket,
6346+
no_signature, unsupported_signature,
6347+
{'SocketType': methods_no_signature & defined},
6348+
{'SocketType': methods_unsupported_signature & defined})
6349+
63316350
def test_stat_module_has_signatures(self):
63326351
import stat
63336352
self._test_module_has_signatures(stat)

0 commit comments

Comments
 (0)