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:

from ctypes import Array
help(Array)

>>> Help on class Array in module _ctypes:
>>>
>>> class Array(_CData)
>>>  |  XXX to be provided   # !!
>>>  |

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

Activity

  1. kostyafarber commented on Aug 6, 2023

    @kostyafarber
    Contributor

    Can I work on this?

  2. tomasr8 commented on Aug 6, 2023

    @tomasr8
    MemberAuthor

    Can I work on this?

    Go ahead!

  3. added a commit that references this issue on Aug 10, 2023
  4. kostyafarber commented on Aug 10, 2023

    @kostyafarber
    Contributor

    @tomasr8 we can close this now as it's been merged. Thanks!

  5. hugovk commented on Aug 10, 2023

    @hugovk
    Member

    Does this need backporting (to 3.11)? Docs things usually are, I'm not sure about docstrings.

  6. tomasr8 commented on Aug 10, 2023

    @tomasr8
    MemberAuthor

    No idea what the general policy is, but searching for merged docstring PRs, I found a couple which did get backported (e.g. #103113)

  7. HarshKakran commented on Aug 23, 2023

    @HarshKakran

    Hey! Is this issue still open?

  8. tomasr8 commented on Aug 23, 2023

    @tomasr8
    MemberAuthor

    Hey! Is this issue still open?

    The PR was ctypes.Array has already been merged, but if you look through the ctypes module, there are more objects with missing docstrings (e.g. _CData). You might wanna have a look at those ;)

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions