Skip to content

Commit 9833052

Browse files
gh-107298: Fix yet more Sphinx warnings in the C API doc (GH-107345)
1 parent ac7a0f8 commit 9833052

19 files changed

+88
-79
lines changed

Doc/c-api/capsule.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ Refer to :ref:`using-capsules` for more information on using these objects.
121121
compared.)
122122
123123
In other words, if :c:func:`PyCapsule_IsValid` returns a true value, calls to
124-
any of the accessors (any function starting with :c:func:`PyCapsule_Get`) are
124+
any of the accessors (any function starting with ``PyCapsule_Get``) are
125125
guaranteed to succeed.
126126
127127
Return a nonzero value if the object is valid and matches the name passed in.

Doc/c-api/init_config.rst

+11-1
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,8 @@ PyStatus
135135
136136
Name of the function which created an error, can be ``NULL``.
137137
138+
.. c:namespace:: NULL
139+
138140
Functions to create a status:
139141
140142
.. c:function:: PyStatus PyStatus_Ok(void)
@@ -210,6 +212,8 @@ PyPreConfig
210212
211213
Structure used to preinitialize Python.
212214
215+
.. c:namespace:: NULL
216+
213217
Function to initialize a preconfiguration:
214218
215219
.. c:function:: void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)
@@ -222,6 +226,8 @@ PyPreConfig
222226
Initialize the preconfiguration with :ref:`Isolated Configuration
223227
<init-isolated-conf>`.
224228
229+
.. c:namespace:: PyPreConfig
230+
225231
Structure fields:
226232
227233
.. c:member:: int allocator
@@ -429,6 +435,8 @@ PyConfig
429435
When done, the :c:func:`PyConfig_Clear` function must be used to release the
430436
configuration memory.
431437
438+
.. c:namespace:: NULL
439+
432440
Structure methods:
433441
434442
.. c:function:: void PyConfig_InitPythonConfig(PyConfig *config)
@@ -527,6 +535,8 @@ PyConfig
527535
The caller of these methods is responsible to handle exceptions (error or
528536
exit) using ``PyStatus_Exception()`` and ``Py_ExitStatusException()``.
529537
538+
.. c:namespace:: PyConfig
539+
530540
Structure fields:
531541
532542
.. c:member:: PyWideStringList argv
@@ -938,7 +948,7 @@ PyConfig
938948
.. c:member:: wchar_t* pythonpath_env
939949
940950
Module search paths (:data:`sys.path`) as a string separated by ``DELIM``
941-
(:data:`os.path.pathsep`).
951+
(:data:`os.pathsep`).
942952
943953
Set by the :envvar:`PYTHONPATH` environment variable.
944954

Doc/c-api/intro.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ and lose important information about the exact cause of the error.
616616
.. index:: single: sum_sequence()
617617

618618
A simple example of detecting exceptions and passing them on is shown in the
619-
:c:func:`sum_sequence` example above. It so happens that this example doesn't
619+
:c:func:`!sum_sequence` example above. It so happens that this example doesn't
620620
need to clean up any owned references when it detects an error. The following
621621
example function shows some error cleanup. First, to remind you why you like
622622
Python, we show the equivalent Python code::

Doc/c-api/memory.rst

+2
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,8 @@ Customize Memory Allocators
431431
432432
Enum used to identify an allocator domain. Domains:
433433
434+
.. c:namespace:: NULL
435+
434436
.. c:macro:: PYMEM_DOMAIN_RAW
435437
436438
Functions:

Doc/c-api/module.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ Module Objects
119119
encoded to 'utf-8'.
120120
121121
.. deprecated:: 3.2
122-
:c:func:`PyModule_GetFilename` raises :c:type:`UnicodeEncodeError` on
122+
:c:func:`PyModule_GetFilename` raises :exc:`UnicodeEncodeError` on
123123
unencodable filenames, use :c:func:`PyModule_GetFilenameObject` instead.
124124
125125

Doc/c-api/none.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ The ``None`` Object
99

1010
Note that the :c:type:`PyTypeObject` for ``None`` is not directly exposed in the
1111
Python/C API. Since ``None`` is a singleton, testing for object identity (using
12-
``==`` in C) is sufficient. There is no :c:func:`PyNone_Check` function for the
12+
``==`` in C) is sufficient. There is no :c:func:`!PyNone_Check` function for the
1313
same reason.
1414

1515

Doc/c-api/object.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ Object Protocol
293293
294294
Normally only class objects, i.e. instances of :class:`type` or a derived
295295
class, are considered classes. However, objects can override this by having
296-
a :attr:`__bases__` attribute (which must be a tuple of base classes).
296+
a :attr:`~class.__bases__` attribute (which must be a tuple of base classes).
297297
298298
299299
.. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls)
@@ -310,10 +310,10 @@ Object Protocol
310310
is an instance of *cls* if its class is a subclass of *cls*.
311311
312312
An instance *inst* can override what is considered its class by having a
313-
:attr:`__class__` attribute.
313+
:attr:`~instance.__class__` attribute.
314314
315315
An object *cls* can override if it is considered a class, and what its base
316-
classes are, by having a :attr:`__bases__` attribute (which must be a tuple
316+
classes are, by having a :attr:`~class.__bases__` attribute (which must be a tuple
317317
of base classes).
318318
319319

Doc/c-api/set.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ or :class:`frozenset` or instances of their subtypes.
110110
.. index:: pair: built-in function; len
111111
112112
Return the length of a :class:`set` or :class:`frozenset` object. Equivalent to
113-
``len(anyset)``. Raises a :exc:`PyExc_SystemError` if *anyset* is not a
113+
``len(anyset)``. Raises a :exc:`SystemError` if *anyset* is not a
114114
:class:`set`, :class:`frozenset`, or an instance of a subtype.
115115
116116
@@ -124,7 +124,7 @@ or :class:`frozenset` or instances of their subtypes.
124124
Return ``1`` if found, ``0`` if not found, and ``-1`` if an error is encountered. Unlike
125125
the Python :meth:`~object.__contains__` method, this function does not automatically
126126
convert unhashable sets into temporary frozensets. Raise a :exc:`TypeError` if
127-
the *key* is unhashable. Raise :exc:`PyExc_SystemError` if *anyset* is not a
127+
the *key* is unhashable. Raise :exc:`SystemError` if *anyset* is not a
128128
:class:`set`, :class:`frozenset`, or an instance of a subtype.
129129
130130
@@ -149,7 +149,7 @@ subtypes but not for instances of :class:`frozenset` or its subtypes.
149149
error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a
150150
:exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~set.discard`
151151
method, this function does not automatically convert unhashable sets into
152-
temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is not an
152+
temporary frozensets. Raise :exc:`SystemError` if *set* is not an
153153
instance of :class:`set` or its subtype.
154154
155155

Doc/c-api/sys.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Operating System Utilities
167167
168168
.. versionchanged:: 3.8
169169
The function now uses the UTF-8 encoding on Windows if
170-
:c:member:`PyConfig.legacy_windows_fs_encoding` is zero;
170+
:c:member:`PyPreConfig.legacy_windows_fs_encoding` is zero;
171171
172172
173173
.. c:function:: char* Py_EncodeLocale(const wchar_t *text, size_t *error_pos)
@@ -209,7 +209,7 @@ Operating System Utilities
209209
210210
.. versionchanged:: 3.8
211211
The function now uses the UTF-8 encoding on Windows if
212-
:c:member:`PyConfig.legacy_windows_fs_encoding` is zero.
212+
:c:member:`PyPreConfig.legacy_windows_fs_encoding` is zero.
213213
214214
215215
.. _systemfunctions:

Doc/c-api/type.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ Type Objects
103103
:c:func:`PyType_AddWatcher` will be called whenever
104104
:c:func:`PyType_Modified` reports a change to *type*. (The callback may be
105105
called only once for a series of consecutive modifications to *type*, if
106-
:c:func:`PyType_Lookup` is not called on *type* between the modifications;
106+
:c:func:`!_PyType_Lookup` is not called on *type* between the modifications;
107107
this is an implementation detail and subject to change.)
108108
109109
An extension should never call ``PyType_Watch`` with a *watcher_id* that was

Doc/c-api/typeobj.rst

+17-16
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ PyObject Slots
485485
--------------
486486

487487
The type object structure extends the :c:type:`PyVarObject` structure. The
488-
:c:member:`~PyVarObject.ob_size` field is used for dynamic types (created by :func:`type_new`,
488+
:c:member:`~PyVarObject.ob_size` field is used for dynamic types (created by :c:func:`!type_new`,
489489
usually called from a class statement). Note that :c:data:`PyType_Type` (the
490490
metatype) initializes :c:member:`~PyTypeObject.tp_itemsize`, which means that its instances (i.e.
491491
type objects) *must* have the :c:member:`~PyVarObject.ob_size` field.
@@ -740,7 +740,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
740740
Before version 3.12, it was not recommended for
741741
:ref:`mutable heap types <heap-types>` to implement the vectorcall
742742
protocol.
743-
When a user sets :attr:`~type.__call__` in Python code, only *tp_call* is
743+
When a user sets :attr:`~object.__call__` in Python code, only *tp_call* is
744744
updated, likely making it inconsistent with the vectorcall function.
745745
Since 3.12, setting ``__call__`` will disable vectorcall optimization
746746
by clearing the :c:macro:`Py_TPFLAGS_HAVE_VECTORCALL` flag.
@@ -1369,8 +1369,8 @@ and :c:data:`PyType_Type` effectively act as defaults.)
13691369
The :c:member:`~PyTypeObject.tp_traverse` pointer is used by the garbage collector to detect
13701370
reference cycles. A typical implementation of a :c:member:`~PyTypeObject.tp_traverse` function
13711371
simply calls :c:func:`Py_VISIT` on each of the instance's members that are Python
1372-
objects that the instance owns. For example, this is function :c:func:`local_traverse` from the
1373-
:mod:`_thread` extension module::
1372+
objects that the instance owns. For example, this is function :c:func:`!local_traverse` from the
1373+
:mod:`!_thread` extension module::
13741374

13751375
static int
13761376
local_traverse(localobject *self, visitproc visit, void *arg)
@@ -1721,7 +1721,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
17211721
called; it may also be initialized to a dictionary containing initial attributes
17221722
for the type. Once :c:func:`PyType_Ready` has initialized the type, extra
17231723
attributes for the type may be added to this dictionary only if they don't
1724-
correspond to overloaded operations (like :meth:`__add__`). Once
1724+
correspond to overloaded operations (like :meth:`~object.__add__`). Once
17251725
initialization for the type has finished, this field should be
17261726
treated as read-only.
17271727

@@ -1818,7 +1818,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
18181818
**Default:**
18191819

18201820
This slot has no default. For :ref:`static types <static-types>`, if the
1821-
field is ``NULL`` then no :attr:`__dict__` gets created for instances.
1821+
field is ``NULL`` then no :attr:`~object.__dict__` gets created for instances.
18221822

18231823
If the :c:macro:`Py_TPFLAGS_MANAGED_DICT` bit is set in the
18241824
:c:member:`~PyTypeObject.tp_dict` field, then
@@ -1830,18 +1830,18 @@ and :c:data:`PyType_Type` effectively act as defaults.)
18301830
18311831
An optional pointer to an instance initialization function.
18321832

1833-
This function corresponds to the :meth:`__init__` method of classes. Like
1834-
:meth:`__init__`, it is possible to create an instance without calling
1835-
:meth:`__init__`, and it is possible to reinitialize an instance by calling its
1836-
:meth:`__init__` method again.
1833+
This function corresponds to the :meth:`~object.__init__` method of classes. Like
1834+
:meth:`!__init__`, it is possible to create an instance without calling
1835+
:meth:`!__init__`, and it is possible to reinitialize an instance by calling its
1836+
:meth:`!__init__` method again.
18371837

18381838
The function signature is::
18391839

18401840
int tp_init(PyObject *self, PyObject *args, PyObject *kwds);
18411841

18421842
The self argument is the instance to be initialized; the *args* and *kwds*
18431843
arguments represent positional and keyword arguments of the call to
1844-
:meth:`__init__`.
1844+
:meth:`~object.__init__`.
18451845

18461846
The :c:member:`~PyTypeObject.tp_init` function, if not ``NULL``, is called when an instance is
18471847
created normally by calling its type, after the type's :c:member:`~PyTypeObject.tp_new` function
@@ -2130,7 +2130,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
21302130
In other words, it is used to implement
21312131
:ref:`vectorcall <vectorcall>` for ``type.__call__``.
21322132
If ``tp_vectorcall`` is ``NULL``, the default call implementation
2133-
using :attr:`__new__` and :attr:`__init__` is used.
2133+
using :meth:`~object.__new__` and :meth:`~object.__init__` is used.
21342134

21352135
**Inheritance:**
21362136

@@ -2329,8 +2329,8 @@ Mapping Object Structures
23292329
.. c:member:: objobjargproc PyMappingMethods.mp_ass_subscript
23302330
23312331
This function is used by :c:func:`PyObject_SetItem`,
2332-
:c:func:`PyObject_DelItem`, :c:func:`PyObject_SetSlice` and
2333-
:c:func:`PyObject_DelSlice`. It has the same signature as
2332+
:c:func:`PyObject_DelItem`, :c:func:`PySequence_SetSlice` and
2333+
:c:func:`PySequence_DelSlice`. It has the same signature as
23342334
:c:func:`!PyObject_SetItem`, but *v* can also be set to ``NULL`` to delete
23352335
an item. If this slot is ``NULL``, the object does not support item
23362336
assignment and deletion.
@@ -2552,7 +2552,7 @@ Async Object Structures
25522552
PyObject *am_aiter(PyObject *self);
25532553

25542554
Must return an :term:`asynchronous iterator` object.
2555-
See :meth:`__anext__` for details.
2555+
See :meth:`~object.__anext__` for details.
25562556

25572557
This slot may be set to ``NULL`` if an object does not implement
25582558
asynchronous iteration protocol.
@@ -2563,7 +2563,8 @@ Async Object Structures
25632563

25642564
PyObject *am_anext(PyObject *self);
25652565

2566-
Must return an :term:`awaitable` object. See :meth:`__anext__` for details.
2566+
Must return an :term:`awaitable` object.
2567+
See :meth:`~object.__anext__` for details.
25672568
This slot may be set to ``NULL``.
25682569

25692570
.. c:member:: sendfunc PyAsyncMethods.am_send

Doc/extending/embedding.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ following two statements before the call to :c:func:`Py_Initialize`::
269269
PyImport_AppendInittab("emb", &PyInit_emb);
270270

271271
These two lines initialize the ``numargs`` variable, and make the
272-
:func:`emb.numargs` function accessible to the embedded Python interpreter.
272+
:func:`!emb.numargs` function accessible to the embedded Python interpreter.
273273
With these extensions, the Python script can do things like
274274

275275
.. code-block:: python

Doc/extending/extending.rst

+12-12
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ The choice of which exception to raise is entirely yours. There are predeclared
197197
C objects corresponding to all built-in Python exceptions, such as
198198
:c:data:`PyExc_ZeroDivisionError`, which you can use directly. Of course, you
199199
should choose exceptions wisely --- don't use :c:data:`PyExc_TypeError` to mean
200-
that a file couldn't be opened (that should probably be :c:data:`PyExc_IOError`).
200+
that a file couldn't be opened (that should probably be :c:data:`PyExc_OSError`).
201201
If something's wrong with the argument list, the :c:func:`PyArg_ParseTuple`
202202
function usually raises :c:data:`PyExc_TypeError`. If you have an argument whose
203203
value must be in a particular range or must satisfy other conditions,
@@ -208,7 +208,7 @@ usually declare a static object variable at the beginning of your file::
208208

209209
static PyObject *SpamError;
210210

211-
and initialize it in your module's initialization function (:c:func:`PyInit_spam`)
211+
and initialize it in your module's initialization function (:c:func:`!PyInit_spam`)
212212
with an exception object::
213213

214214
PyMODINIT_FUNC
@@ -354,7 +354,7 @@ The method table must be referenced in the module definition structure::
354354

355355
This structure, in turn, must be passed to the interpreter in the module's
356356
initialization function. The initialization function must be named
357-
:c:func:`PyInit_name`, where *name* is the name of the module, and should be the
357+
:c:func:`!PyInit_name`, where *name* is the name of the module, and should be the
358358
only non-\ ``static`` item defined in the module file::
359359

360360
PyMODINIT_FUNC
@@ -368,7 +368,7 @@ declares any special linkage declarations required by the platform, and for C++
368368
declares the function as ``extern "C"``.
369369

370370
When the Python program imports module :mod:`!spam` for the first time,
371-
:c:func:`PyInit_spam` is called. (See below for comments about embedding Python.)
371+
:c:func:`!PyInit_spam` is called. (See below for comments about embedding Python.)
372372
It calls :c:func:`PyModule_Create`, which returns a module object, and
373373
inserts built-in function objects into the newly created module based upon the
374374
table (an array of :c:type:`PyMethodDef` structures) found in the module definition.
@@ -378,7 +378,7 @@ certain errors, or return ``NULL`` if the module could not be initialized
378378
satisfactorily. The init function must return the module object to its caller,
379379
so that it then gets inserted into ``sys.modules``.
380380

381-
When embedding Python, the :c:func:`PyInit_spam` function is not called
381+
When embedding Python, the :c:func:`!PyInit_spam` function is not called
382382
automatically unless there's an entry in the :c:data:`PyImport_Inittab` table.
383383
To add the module to the initialization table, use :c:func:`PyImport_AppendInittab`,
384384
optionally followed by an import of the module::
@@ -1220,13 +1220,13 @@ the module and retrieving its C API pointers; client modules only have to call
12201220
this macro before accessing the C API.
12211221

12221222
The exporting module is a modification of the :mod:`!spam` module from section
1223-
:ref:`extending-simpleexample`. The function :func:`spam.system` does not call
1223+
:ref:`extending-simpleexample`. The function :func:`!spam.system` does not call
12241224
the C library function :c:func:`system` directly, but a function
1225-
:c:func:`PySpam_System`, which would of course do something more complicated in
1225+
:c:func:`!PySpam_System`, which would of course do something more complicated in
12261226
reality (such as adding "spam" to every command). This function
1227-
:c:func:`PySpam_System` is also exported to other extension modules.
1227+
:c:func:`!PySpam_System` is also exported to other extension modules.
12281228

1229-
The function :c:func:`PySpam_System` is a plain C function, declared
1229+
The function :c:func:`!PySpam_System` is a plain C function, declared
12301230
``static`` like everything else::
12311231

12321232
static int
@@ -1288,7 +1288,7 @@ function must take care of initializing the C API pointer array::
12881288
}
12891289

12901290
Note that ``PySpam_API`` is declared ``static``; otherwise the pointer
1291-
array would disappear when :func:`PyInit_spam` terminates!
1291+
array would disappear when :c:func:`!PyInit_spam` terminates!
12921292

12931293
The bulk of the work is in the header file :file:`spammodule.h`, which looks
12941294
like this::
@@ -1342,8 +1342,8 @@ like this::
13421342
#endif /* !defined(Py_SPAMMODULE_H) */
13431343

13441344
All that a client module must do in order to have access to the function
1345-
:c:func:`PySpam_System` is to call the function (or rather macro)
1346-
:c:func:`import_spam` in its initialization function::
1345+
:c:func:`!PySpam_System` is to call the function (or rather macro)
1346+
:c:func:`!import_spam` in its initialization function::
13471347

13481348
PyMODINIT_FUNC
13491349
PyInit_client(void)

0 commit comments

Comments
 (0)