Skip to content

Commit 092c896

Browse files
authored
gh-157208: Fix the ctypes.util.struct documentation (GH-157209)
1 parent 34439b8 commit 092c896

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

Doc/library/ctypes.rst

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ Specifying function pointers using type annotations
708708

709709
@wrap_dll_function(dll_to_wrap)
710710
def function_ptr_name(arg_name: ctypes_type, ...) -> ctypes_type:
711-
"""Optional docstring. There should be no function body."""
711+
"""Optional docstring. There should be no function body."""
712712

713713
The body of the decorated function is ignored, and any parameters that are
714714
missing type annotations are skipped. The names of the parameters are ignored
@@ -728,7 +728,7 @@ Specifying function pointers using type annotations
728728

729729
@wrap_dll_function(ctypes.pythonapi)
730730
def PyObject_GetAttrString(op: ctypes.py_object, attr: ctypes.c_char_p) -> ctypes.py_object:
731-
pass
731+
pass
732732

733733
PyObject_GetAttrString(42, b"real")
734734

@@ -3207,7 +3207,7 @@ fields, or any other data types containing pointer type fields.
32073207
that should be merged into a containing structure or union.
32083208

32093209

3210-
.. decorator:: struct(*, align=None, layout, endian='native', pack=None)
3210+
.. decorator:: struct(*, align=None, layout=None, endian='native', pack=None)
32113211
:module: ctypes.util
32123212

32133213
A :term:`decorator` that allows generating structure types using an
@@ -3244,14 +3244,18 @@ fields, or any other data types containing pointer type fields.
32443244

32453245
.. code-block:: python
32463246
3247+
from typing import Annotated
3248+
from ctypes import c_ssize_t, c_void_p
3249+
from ctypes.util import struct, CFieldInfo
3250+
32473251
@struct
32483252
class PyObject:
3249-
ob_refcnt: c_ssize_t
3250-
ob_type: c_void_p
3253+
ob_refcnt: c_ssize_t
3254+
ob_type: c_void_p
32513255
32523256
@struct
32533257
class PyHovercraftObject:
3254-
ob_base: Annotated[PyObject, CFieldInfo(anonymous=True)]
3258+
ob_base: Annotated[PyObject, CFieldInfo(anonymous=True)]
32553259
32563260
.. versionadded:: next
32573261

0 commit comments

Comments
 (0)