Skip to content

Commit 06413d3

Browse files
committed
gh-157208: Fix the ctypes.util.struct documentation
The anonymous-field example used Annotated, CFieldInfo, c_ssize_t and c_void_p without importing any of them, so it raised NameError when copied out of the page. Add the imports and indent the example body four spaces to match the example above it. The signature line showed layout without its default, rendering an optional parameter as required.
1 parent 1ac3bfa commit 06413d3

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

Doc/library/ctypes.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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)