Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ctypes: Add docstring for ctypes.Array #107689

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tomasr8 opened this issue Aug 6, 2023 · 7 comments
Closed

ctypes: Add docstring for ctypes.Array #107689

tomasr8 opened this issue Aug 6, 2023 · 7 comments
Labels
docs Documentation in the Doc dir easy topic-ctypes

Comments

@tomasr8
Copy link
Member

tomasr8 commented Aug 6, 2023

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

@tomasr8 tomasr8 added the docs Documentation in the Doc dir label Aug 6, 2023
@kostyafarber
Copy link
Contributor

Can I work on this?

@tomasr8
Copy link
Member Author

tomasr8 commented Aug 6, 2023

Can I work on this?

Go ahead!

@kostyafarber
Copy link
Contributor

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

@hugovk
Copy link
Member

hugovk commented Aug 10, 2023

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

@tomasr8
Copy link
Member Author

tomasr8 commented Aug 10, 2023

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

@HarshKakran
Copy link

Hey! Is this issue still open?

@tomasr8
Copy link
Member Author

tomasr8 commented Aug 23, 2023

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
Labels
docs Documentation in the Doc dir easy topic-ctypes
Projects
None yet
Development

No branches or pull requests

6 participants