Skip to content

ctypes.util.struct example does not run and layout looks required #157208

Description

@fedonman

Documentation

The second @struct example in Doc/library/ctypes.rst cannot be run: it uses Annotated, CFieldInfo, c_ssize_t and c_void_p, and the page imports none of them. Carrying over the imports from the first example directly above it is not enough either.

$ ./python -c '
from ctypes.util import struct
from ctypes import c_int

@struct
class PyObject:
   ob_refcnt: c_ssize_t
   ob_type: c_void_p
'
Traceback (most recent call last):
  ...
  File "<string>", line 7, in __annotate__
    ob_refcnt: c_ssize_t
               ^^^^^^^^^
NameError: name 'c_ssize_t' is not defined

The same entry's signature line is struct(*, align=None, layout, endian='native', pack=None), which renders layout as a required parameter. ctypes.util.struct gives it a default:

$ ./python -c "import inspect, ctypes.util; print(inspect.signature(ctypes.util.struct))"
(class_or_none=None, /, *, align=None, layout=None, endian='native', pack=None)

Expected: the example runs as written, and layout is documented as layout=None.

Linked PRs

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions