Skip to content

ctypes: Add docstring for ctypes.Array #107689

Description

@tomasr8

Documentation

The Array class from the ctypes module doesn't have a proper docstring:

fromctypesimportArrayhelp(Array)
>>>HelponclassArrayinmodule_ctypes:
>>>>>>classArray(_CData)
>>>|XXXtobeprovided# !!>>>|

Though the class is documented in the docs so we could just reuse that description.

Feel free to pick up this issue :) If you're new to the C internals, here's a small guide to help you get started:

ctypes.Array is a class implemented in C defined in Modules/_ctypes/_ctypes.c. Here is the current docstring definition:

Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */
PyDoc_STR("XXX to be provided"), /* tp_doc */
(traverseproc)PyCData_traverse, /* tp_traverse */

To update the docstring, we could simply change the argument of PyDoc_STR(...) but if the docstring is longer it's better to use PyDoc_STRVAR to create a separate variable with the new docstring:

PyDoc_STRVAR(array_doc,
"Abstract base class for arrays.\n""\n""The recommended way to create ...");

then you substitute it back instead of PyDoc_STR:

Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* tp_flags */ - PyDoc_STR("XXX to be provided"), /* tp_doc */ + array_doc, /* tp_doc */ 
(traverseproc)PyCData_traverse, 

To test that it worked, rebuild python and check the docstring ;)

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions