[3.7] bpo-38387: Formally document PyDoc_STRVAR and PyDoc_STR macros (GH-16607) (GH-19728)

Adds a short description of `PyDoc_STRVAR` and `PyDoc_STR` to "Useful macros" section of C-API docs.

Currently, there is [one lone mention](https://docs.python.org/3/c-api/module.html?highlight=pydoc_strvarGH-c.PyModuleDef) in the C-API reference, despite the fact that `PyDoc_STRVAR` is ubiquitous to `Modules/`.

Additionally, this properly uses `c:macro` within `Doc/c-api/module.rst` to link..
(cherry picked from commit b54e46cb57)

Co-authored-by: Brad Solomon <brad.solomon.1124@gmail.com>
This commit is contained in:
Zachary Ware 2020-04-26 21:46:06 -05:00 committed by GitHub
parent fd32a0e2ee
commit 70ba81459e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View File

@ -162,6 +162,39 @@ complete listing.
.. versionadded:: 3.4
.. c:macro:: PyDoc_STRVAR(name, str)
Creates a variable with name ``name`` that can be used in docstrings.
If Python is built without docstrings, the value will be empty.
Use :c:macro:`PyDoc_STRVAR` for docstrings to support building
Python without docstrings, as specified in :pep:`7`.
Example::
PyDoc_STRVAR(pop_doc, "Remove and return the rightmost element.");
static PyMethodDef deque_methods[] = {
// ...
{"pop", (PyCFunction)deque_pop, METH_NOARGS, pop_doc},
// ...
}
.. c:macro:: PyDoc_STR(str)
Creates a docstring for the given input string or an empty string
if docstrings are disabled.
Use :c:macro:`PyDoc_STR` in specifying docstrings to support
building Python without docstrings, as specified in :pep:`7`.
Example::
static PyMethodDef pysqlite_row_methods[] = {
{"keys", (PyCFunction)pysqlite_row_keys, METH_NOARGS,
PyDoc_STR("Returns the keys of the row.")},
{NULL, NULL}
};
.. _api-objects:

View File

@ -153,7 +153,7 @@ or request "multi-phase initialization" by returning the definition struct itsel
.. c:member:: const char *m_doc
Docstring for the module; usually a docstring variable created with
:c:func:`PyDoc_STRVAR` is used.
:c:macro:`PyDoc_STRVAR` is used.
.. c:member:: Py_ssize_t m_size

View File

@ -0,0 +1 @@
Document :c:macro:`PyDoc_STRVAR` macro in the C-API reference.