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
Documentation
The second
@structexample inDoc/library/ctypes.rstcannot be run: it usesAnnotated,CFieldInfo,c_ssize_tandc_void_p, and the page imports none of them. Carrying over the imports from the first example directly above it is not enough either.The same entry's signature line is
struct(*, align=None, layout, endian='native', pack=None), which renders layout as a required parameter.ctypes.util.structgives it a default:Expected: the example runs as written, and layout is documented as
layout=None.Linked PRs
ctypes.util.structdocumentation #157209