8000 [3.8] bpo-38387: Formally document PyDoc_STRVAR and PyDoc_STR macros … · python/cpython@ca5649c · GitHub
[go: up one dir, main page]

Skip to content

Commit ca5649c

Browse files
authored
[3.8] bpo-38387: Formally document PyDoc_STRVAR and PyDoc_STR macros (GH-16607) (GH-19727)
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 b54e46c) Authored-by: Brad Solomon <brad.solomon.1124@gmail.com>
1 parent 179f22c commit ca5649c

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

Doc/c-api/intro.rst

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,39 @@ complete listing.
174174
.. versionchanged:: 3.8
175175
MSVC support was added.
176176

177+
.. c:macro:: PyDoc_STRVAR(name, str)
178+
179+
Creates a variable with name ``name`` that can be used in docstrings.
180+
If Python is built without docstrings, the value will be empty.
181+
182+
Use :c:macro:`PyDoc_STRVAR` for docstrings to support building
183+
Python without docstrings, as specified in :pep:`7`.
184+
185+
Example::
186+
187+
PyDoc_STRVAR(pop_doc, "Remove and return the rightmost element.");
188+
189+
static PyMethodDef deque_methods[] = {
190+
// ...
191+
{"pop", (PyCFunction)deque_pop, METH_NOARGS, pop_doc},
192+
// ...
193+
}
194+
195+
.. c:macro:: PyDoc_STR(str)
196+
197+
Creates a docstring for the given input string or an empty string
198+
if docstrings are disabled.
199< 10000 code class="diff-text syntax-highlighted-line addition">+
200+
Use :c:macro:`PyDoc_STR` in specifying docstrings to support
201+
building Python without docstrings, as specified in :pep:`7`.
202+
203+
Example::
204+
205+
static PyMethodDef pysqlite_row_methods[] = {
206+
{"keys", (PyCFunction)pysqlite_row_keys, METH_NOARGS,
207+
PyDoc_STR("Returns the keys of the row.")},
208+
{NULL, NULL}
209+
};
177210

178211
.. _api-objects:
179212

Doc/c-api/module.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ or request "multi-phase initialization" by returning the definition struct itsel
153153
.. c:member:: const char *m_doc
154154
155155
Docstring for the module; usually a docstring variable created with
156-
:c:func:`PyDoc_STRVAR` is used.
156+
:c:macro:`PyDoc_STRVAR` is used.
157157
158158
.. c:member:: Py_ssize_t m_size
159159
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document :c:macro:`PyDoc_STRVAR` macro in the C-API reference.

0 commit comments

Comments
 (0)
0