When creating a C extension to Python, is it possible to be able to somehow write comments that are exposed as docstrings to users of the extension?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Docstrings for types can be included as the
tp_docmember in thePyTypeObjectstructure, see an example in the docs.Docstrings for functions can be included in the
ml_docfield of the module’s method table. If you want your docstrings to be “physically close” to the actual functions, you could include string constants above your function definitions which you reference in the method table.Docstrings for methods can be assigned to the
docfield in the type’s member table.Docstrings for modules can be passed as a parameter to the
Py_InitModule3()orPy_InitModule4()functions.UPDATE: Python3 does not support
Py_InitModule3(), and the method has been replaced withPyModule_Create().