Skip to content

Commit

Permalink
pythongh-107298: Fix yet more Sphinx warnings in the C API doc
Browse files Browse the repository at this point in the history
  • Loading branch information
serhiy-storchaka committed Jul 27, 2023
1 parent f84d77b commit cbcd3a9
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Doc/c-api/capsule.rst
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Refer to :ref:`using-capsules` for more information on using these objects.
compared.)
In other words, if :c:func:`PyCapsule_IsValid` returns a true value, calls to
any of the accessors (any function starting with :c:func:`PyCapsule_Get`) are
any of the accessors (any function starting with ``PyCapsule_Get``) are
guaranteed to succeed.
Return a nonzero value if the object is valid and matches the name passed in.
Expand Down
12 changes: 11 additions & 1 deletion Doc/c-api/init_config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ PyStatus
Name of the function which created an error, can be ``NULL``.
.. c:namespace:: NULL
Functions to create a status:
.. c:function:: PyStatus PyStatus_Ok(void)
Expand Down Expand Up @@ -210,6 +212,8 @@ PyPreConfig
Structure used to preinitialize Python.
.. c:namespace:: NULL
Function to initialize a preconfiguration:
.. c:function:: void PyPreConfig_InitPythonConfig(PyPreConfig *preconfig)
Expand All @@ -222,6 +226,8 @@ PyPreConfig
Initialize the preconfiguration with :ref:`Isolated Configuration
<init-isolated-conf>`.
.. c:namespace:: PyPreConfig
Structure fields:
.. c:member:: int allocator
Expand Down Expand Up @@ -429,6 +435,8 @@ PyConfig
When done, the :c:func:`PyConfig_Clear` function must be used to release the
configuration memory.
.. c:namespace:: NULL
Structure methods:
.. c:function:: void PyConfig_InitPythonConfig(PyConfig *config)
Expand Down Expand Up @@ -527,6 +535,8 @@ PyConfig
The caller of these methods is responsible to handle exceptions (error or
exit) using ``PyStatus_Exception()`` and ``Py_ExitStatusException()``.
.. c:namespace:: PyConfig
Structure fields:
.. c:member:: PyWideStringList argv
Expand Down Expand Up @@ -938,7 +948,7 @@ PyConfig
.. c:member:: wchar_t* pythonpath_env
Module search paths (:data:`sys.path`) as a string separated by ``DELIM``
(:data:`os.path.pathsep`).
(:data:`os.pathsep`).
Set by the :envvar:`PYTHONPATH` environment variable.
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ and lose important information about the exact cause of the error.
.. index:: single: sum_sequence()

A simple example of detecting exceptions and passing them on is shown in the
:c:func:`sum_sequence` example above. It so happens that this example doesn't
:c:func:`!sum_sequence` example above. It so happens that this example doesn't
need to clean up any owned references when it detects an error. The following
example function shows some error cleanup. First, to remind you why you like
Python, we show the equivalent Python code::
Expand Down
2 changes: 2 additions & 0 deletions Doc/c-api/memory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,8 @@ Customize Memory Allocators
Enum used to identify an allocator domain. Domains:
.. c:namespace:: NULL
.. c:macro:: PYMEM_DOMAIN_RAW
Functions:
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Module Objects
encoded to 'utf-8'.
.. deprecated:: 3.2
:c:func:`PyModule_GetFilename` raises :c:type:`UnicodeEncodeError` on
:c:func:`PyModule_GetFilename` raises :exc:`UnicodeEncodeError` on
unencodable filenames, use :c:func:`PyModule_GetFilenameObject` instead.
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/none.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ The ``None`` Object

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


Expand Down
6 changes: 3 additions & 3 deletions Doc/c-api/object.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ Object Protocol
Normally only class objects, i.e. instances of :class:`type` or a derived
class, are considered classes. However, objects can override this by having
a :attr:`__bases__` attribute (which must be a tuple of base classes).
a :attr:`~class.__bases__` attribute (which must be a tuple of base classes).
.. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls)
Expand All @@ -310,10 +310,10 @@ Object Protocol
is an instance of *cls* if its class is a subclass of *cls*.
An instance *inst* can override what is considered its class by having a
:attr:`__class__` attribute.
:attr:`~instance.__class__` attribute.
An object *cls* can override if it is considered a class, and what its base
classes are, by having a :attr:`__bases__` attribute (which must be a tuple
classes are, by having a :attr:`~class.__bases__` attribute (which must be a tuple
of base classes).
Expand Down
6 changes: 3 additions & 3 deletions Doc/c-api/set.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ or :class:`frozenset` or instances of their subtypes.
.. index:: pair: built-in function; len
Return the length of a :class:`set` or :class:`frozenset` object. Equivalent to
``len(anyset)``. Raises a :exc:`PyExc_SystemError` if *anyset* is not a
``len(anyset)``. Raises a :exc:`SystemError` if *anyset* is not a
:class:`set`, :class:`frozenset`, or an instance of a subtype.
Expand All @@ -124,7 +124,7 @@ or :class:`frozenset` or instances of their subtypes.
Return ``1`` if found, ``0`` if not found, and ``-1`` if an error is encountered. Unlike
the Python :meth:`~object.__contains__` method, this function does not automatically
convert unhashable sets into temporary frozensets. Raise a :exc:`TypeError` if
the *key* is unhashable. Raise :exc:`PyExc_SystemError` if *anyset* is not a
the *key* is unhashable. Raise :exc:`SystemError` if *anyset* is not a
:class:`set`, :class:`frozenset`, or an instance of a subtype.
Expand All @@ -149,7 +149,7 @@ subtypes but not for instances of :class:`frozenset` or its subtypes.
error is encountered. Does not raise :exc:`KeyError` for missing keys. Raise a
:exc:`TypeError` if the *key* is unhashable. Unlike the Python :meth:`~set.discard`
method, this function does not automatically convert unhashable sets into
temporary frozensets. Raise :exc:`PyExc_SystemError` if *set* is not an
temporary frozensets. Raise :exc:`SystemError` if *set* is not an
instance of :class:`set` or its subtype.
Expand Down
4 changes: 2 additions & 2 deletions Doc/c-api/sys.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ Operating System Utilities
.. versionchanged:: 3.8
The function now uses the UTF-8 encoding on Windows if
:c:member:`PyConfig.legacy_windows_fs_encoding` is zero;
:c:member:`PyPreConfig.legacy_windows_fs_encoding` is zero;
.. c:function:: char* Py_EncodeLocale(const wchar_t *text, size_t *error_pos)
Expand Down Expand Up @@ -209,7 +209,7 @@ Operating System Utilities
.. versionchanged:: 3.8
The function now uses the UTF-8 encoding on Windows if
:c:member:`PyConfig.legacy_windows_fs_encoding` is zero.
:c:member:`PyPreConfig.legacy_windows_fs_encoding` is zero.
.. _systemfunctions:
Expand Down
2 changes: 1 addition & 1 deletion Doc/c-api/type.rst
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ Type Objects
:c:func:`PyType_AddWatcher` will be called whenever
:c:func:`PyType_Modified` reports a change to *type*. (The callback may be
called only once for a series of consecutive modifications to *type*, if
:c:func:`PyType_Lookup` is not called on *type* between the modifications;
:c:func:`_PyType_Lookup` is not called on *type* between the modifications;
this is an implementation detail and subject to change.)
An extension should never call ``PyType_Watch`` with a *watcher_id* that was
Expand Down
33 changes: 17 additions & 16 deletions Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ PyObject Slots
--------------

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

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

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

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

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

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

The function signature is::

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

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

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

**Inheritance:**

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

Must return an :term:`asynchronous iterator` object.
See :meth:`__anext__` for details.
See :meth:`~object.__anext__` for details.

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

PyObject *am_anext(PyObject *self);

Must return an :term:`awaitable` object. See :meth:`__anext__` for details.
Must return an :term:`awaitable` object.
See :meth:`~object.__anext__` for details.
This slot may be set to ``NULL``.

.. c:member:: sendfunc PyAsyncMethods.am_send
Expand Down
4 changes: 2 additions & 2 deletions Doc/howto/descriptor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -836,8 +836,8 @@ and if they define :meth:`__set_name__`, that method is called with two
arguments. The *owner* is the class where the descriptor is used, and the
*name* is the class variable the descriptor was assigned to.

The implementation details are in :c:func:`type_new()` and
:c:func:`set_names()` in :source:`Objects/typeobject.c`.
The implementation details are in :c:func:`!type_new` and
:c:func:`!set_names` in :source:`Objects/typeobject.c`.

Since the update logic is in :meth:`type.__new__`, notifications only take
place at the time of class creation. If descriptors are added to the class
Expand Down

0 comments on commit cbcd3a9

Please sign in to comment.