Skip to content

socket.socket.sendmsg() exposes unrepresentable Argument Clinic defaults #155621

Description

@lpyu001

Bug report

Description

The Argument Clinic definition for socket.socket.sendmsg() uses the C value
NULL as the declared default for both ancdata and address:

ancdata as cmsg_arg: object = NULL
flags: int = 0
address as addr_arg: object = NULL

Argument Clinic therefore generates <unrepresentable> as their Python
defaults. This exposes an inaccurate text signature and prevents
inspect.signature() from producing a signature for the method.

Both defaults have natural Python representations:

  • an omitted ancdata is handled as an empty sequence, so its Python default
    is ();
  • an omitted address is handled like None, and explicitly passing None
    is supported.

Minimal reproducer

Run on a platform that provides socket.socket.sendmsg():

import inspect
import socket

print(socket.socket.sendmsg.__text_signature__)
print(inspect.signature(socket.socket.sendmsg))

Actual behavior

The generated signature contains:

ancdata=<unrepresentable>
address=<unrepresentable>

inspect.signature() raises:

ValueError: <method 'sendmsg' of '_socket.socket' objects> builtin has invalid signature

Nevertheless, omitting both arguments is valid:

import socket

left, right = socket.socketpair()
with left, right:
    print(left.sendmsg([b"x"]))
    print(right.recv(1))
1
b'x'

Expected behavior

The generated text signature should use representable Python defaults, and
inspect.signature() should return a valid signature equivalent to:

(self, buffers, ancdata=(), flags=0, address=None, /)

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtopic-socketRelated to the socket, socketserver and selectors modulestype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions