Skip to content

Commit 04873f3

Browse files
Fix also Doc/extending/.
1 parent 1858649 commit 04873f3

File tree

9 files changed

+44
-46
lines changed

9 files changed

+44
-46
lines changed

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/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)

Doc/extending/newtypes.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,9 @@ be read-only or read-write. The structures in the table are defined as::
286286

287287
For each entry in the table, a :term:`descriptor` will be constructed and added to the
288288
type which will be able to extract a value from the instance structure. The
289-
:attr:`type` field should contain a type code like :c:macro:`Py_T_INT` or
289+
:c:member:`~PyMemberDef.type` field should contain a type code like :c:macro:`Py_T_INT` or
290290
:c:macro:`Py_T_DOUBLE`; the value will be used to determine how to
291-
convert Python values to and from C values. The :attr:`flags` field is used to
291+
convert Python values to and from C values. The :c:member:`~PyMemberDef.flags` field is used to
292292
store flags which control how the attribute can be accessed: you can set it to
293293
:c:macro:`Py_READONLY` to prevent Python code from setting it.
294294

@@ -298,7 +298,7 @@ have an associated doc string simply by providing the text in the table. An
298298
application can use the introspection API to retrieve the descriptor from the
299299
class object, and get the doc string using its :attr:`__doc__` attribute.
300300

301-
As with the :c:member:`~PyTypeObject.tp_methods` table, a sentinel entry with a :attr:`name` value
301+
As with the :c:member:`~PyTypeObject.tp_methods` table, a sentinel entry with a :c:member:`~PyMethodDef.name` value
302302
of ``NULL`` is required.
303303

304304
.. XXX Descriptors need to be explained in more detail somewhere, but not here.
@@ -323,7 +323,7 @@ called, so that if you do need to extend their functionality, you'll understand
323323
what needs to be done.
324324

325325
The :c:member:`~PyTypeObject.tp_getattr` handler is called when the object requires an attribute
326-
look-up. It is called in the same situations where the :meth:`__getattr__`
326+
look-up. It is called in the same situations where the :meth:`~object.__getattr__`
327327
method of a class would be called.
328328

329329
Here is an example::
@@ -342,8 +342,8 @@ Here is an example::
342342
return NULL;
343343
}
344344

345-
The :c:member:`~PyTypeObject.tp_setattr` handler is called when the :meth:`__setattr__` or
346-
:meth:`__delattr__` method of a class instance would be called. When an
345+
The :c:member:`~PyTypeObject.tp_setattr` handler is called when the :meth:`~object.__setattr__` or
346+
:meth:`~object.__delattr__` method of a class instance would be called. When an
347347
attribute should be deleted, the third parameter will be ``NULL``. Here is an
348348
example that simply raises an exception; if this were really all you wanted, the
349349
:c:member:`~PyTypeObject.tp_setattr` handler should be set to ``NULL``. ::
@@ -364,7 +364,7 @@ Object Comparison
364364

365365
The :c:member:`~PyTypeObject.tp_richcompare` handler is called when comparisons are needed. It is
366366
analogous to the :ref:`rich comparison methods <richcmpfuncs>`, like
367-
:meth:`__lt__`, and also called by :c:func:`PyObject_RichCompare` and
367+
:meth:`!__lt__`, and also called by :c:func:`PyObject_RichCompare` and
368368
:c:func:`PyObject_RichCompareBool`.
369369

370370
This function is called with two Python objects and the operator as arguments,
@@ -505,7 +505,7 @@ These functions provide support for the iterator protocol. Both handlers
505505
take exactly one parameter, the instance for which they are being called,
506506
and return a new reference. In the case of an error, they should set an
507507
exception and return ``NULL``. :c:member:`~PyTypeObject.tp_iter` corresponds
508-
to the Python :meth:`__iter__` method, while :c:member:`~PyTypeObject.tp_iternext`
508+
to the Python :meth:`~object.__iter__` method, while :c:member:`~PyTypeObject.tp_iternext`
509509
corresponds to the Python :meth:`~iterator.__next__` method.
510510

511511
Any :term:`iterable` object must implement the :c:member:`~PyTypeObject.tp_iter`

Doc/extending/newtypes_tutorial.rst

+16-16
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ only used for variable-sized objects and should otherwise be zero.
145145
:c:member:`~PyTypeObject.tp_basicsize` as its base type, you may have problems with multiple
146146
inheritance. A Python subclass of your type will have to list your type first
147147
in its :attr:`~class.__bases__`, or else it will not be able to call your type's
148-
:meth:`__new__` method without getting an error. You can avoid this problem by
148+
:meth:`~object.__new__` method without getting an error. You can avoid this problem by
149149
ensuring that your type has a larger value for :c:member:`~PyTypeObject.tp_basicsize` than its
150150
base type does. Most of the time, this will be true anyway, because either your
151151
base type will be :class:`object`, or else you will be adding data members to
@@ -164,14 +164,14 @@ We provide a doc string for the type in :c:member:`~PyTypeObject.tp_doc`. ::
164164
.tp_doc = PyDoc_STR("Custom objects"),
165165

166166
To enable object creation, we have to provide a :c:member:`~PyTypeObject.tp_new`
167-
handler. This is the equivalent of the Python method :meth:`__new__`, but
167+
handler. This is the equivalent of the Python method :meth:`~object.__new__`, but
168168
has to be specified explicitly. In this case, we can just use the default
169169
implementation provided by the API function :c:func:`PyType_GenericNew`. ::
170170

171171
.tp_new = PyType_GenericNew,
172172

173173
Everything else in the file should be familiar, except for some code in
174-
:c:func:`PyInit_custom`::
174+
:c:func:`!PyInit_custom`::
175175

176176
if (PyType_Ready(&CustomType) < 0)
177177
return;
@@ -218,7 +218,7 @@ Of course, the current Custom type is pretty uninteresting. It has no data and
218218
doesn't do anything. It can't even be subclassed.
219219

220220
.. note::
221-
While this documentation showcases the standard :mod:`distutils` module
221+
While this documentation showcases the standard :mod:`!distutils` module
222222
for building C extensions, it is recommended in real-world use cases to
223223
use the newer and better-maintained ``setuptools`` library. Documentation
224224
on how to do this is out of scope for this document and can be found in
@@ -270,7 +270,7 @@ This method first clears the reference counts of the two Python attributes.
270270
``NULL`` (which might happen here if ``tp_new`` failed midway). It then
271271
calls the :c:member:`~PyTypeObject.tp_free` member of the object's type
272272
(computed by ``Py_TYPE(self)``) to free the object's memory. Note that
273-
the object's type might not be :class:`CustomType`, because the object may
273+
the object's type might not be :class:`!CustomType`, because the object may
274274
be an instance of a subclass.
275275

276276
.. note::
@@ -309,7 +309,7 @@ and install it in the :c:member:`~PyTypeObject.tp_new` member::
309309
.tp_new = Custom_new,
310310

311311
The ``tp_new`` handler is responsible for creating (as opposed to initializing)
312-
objects of the type. It is exposed in Python as the :meth:`__new__` method.
312+
objects of the type. It is exposed in Python as the :meth:`~object.__new__` method.
313313
It is not required to define a ``tp_new`` member, and indeed many extension
314314
types will simply reuse :c:func:`PyType_GenericNew` as done in the first
315315
version of the :class:`!Custom` type above. In this case, we use the ``tp_new``
@@ -343,7 +343,7 @@ result against ``NULL`` before proceeding.
343343

344344
.. note::
345345
If you are creating a co-operative :c:member:`~PyTypeObject.tp_new` (one
346-
that calls a base type's :c:member:`~PyTypeObject.tp_new` or :meth:`__new__`),
346+
that calls a base type's :c:member:`~PyTypeObject.tp_new` or :meth:`~object.__new__`),
347347
you must *not* try to determine what method to call using method resolution
348348
order at runtime. Always statically determine what type you are going to
349349
call, and call its :c:member:`~PyTypeObject.tp_new` directly, or via
@@ -386,14 +386,14 @@ by filling the :c:member:`~PyTypeObject.tp_init` slot. ::
386386
.tp_init = (initproc) Custom_init,
387387

388388
The :c:member:`~PyTypeObject.tp_init` slot is exposed in Python as the
389-
:meth:`__init__` method. It is used to initialize an object after it's
389+
:meth:`~object.__init__` method. It is used to initialize an object after it's
390390
created. Initializers always accept positional and keyword arguments,
391391
and they should return either ``0`` on success or ``-1`` on error.
392392

393393
Unlike the ``tp_new`` handler, there is no guarantee that ``tp_init``
394394
is called at all (for example, the :mod:`pickle` module by default
395-
doesn't call :meth:`__init__` on unpickled instances). It can also be
396-
called multiple times. Anyone can call the :meth:`__init__` method on
395+
doesn't call :meth:`~object.__init__` on unpickled instances). It can also be
396+
called multiple times. Anyone can call the :meth:`!__init__` method on
397397
our objects. For this reason, we have to be extra careful when assigning
398398
the new attribute values. We might be tempted, for example to assign the
399399
``first`` member like this::
@@ -706,8 +706,8 @@ participate in cycles::
706706
}
707707

708708
For each subobject that can participate in cycles, we need to call the
709-
:c:func:`visit` function, which is passed to the traversal method. The
710-
:c:func:`visit` function takes as arguments the subobject and the extra argument
709+
:c:func:`!visit` function, which is passed to the traversal method. The
710+
:c:func:`!visit` function takes as arguments the subobject and the extra argument
711711
*arg* passed to the traversal method. It returns an integer value that must be
712712
returned if it is non-zero.
713713

@@ -789,9 +789,9 @@ types. It is easiest to inherit from the built in types, since an extension can
789789
easily use the :c:type:`PyTypeObject` it needs. It can be difficult to share
790790
these :c:type:`PyTypeObject` structures between extension modules.
791791

792-
In this example we will create a :class:`SubList` type that inherits from the
792+
In this example we will create a :class:`!SubList` type that inherits from the
793793
built-in :class:`list` type. The new type will be completely compatible with
794-
regular lists, but will have an additional :meth:`increment` method that
794+
regular lists, but will have an additional :meth:`!increment` method that
795795
increases an internal counter:
796796

797797
.. code-block:: pycon
@@ -821,7 +821,7 @@ The primary difference for derived type objects is that the base type's
821821
object structure must be the first value. The base type will already include
822822
the :c:func:`PyObject_HEAD` at the beginning of its structure.
823823

824-
When a Python object is a :class:`SubList` instance, its ``PyObject *`` pointer
824+
When a Python object is a :class:`!SubList` instance, its ``PyObject *`` pointer
825825
can be safely cast to both ``PyListObject *`` and ``SubListObject *``::
826826

827827
static int
@@ -833,7 +833,7 @@ can be safely cast to both ``PyListObject *`` and ``SubListObject *``::
833833
return 0;
834834
}
835835

836-
We see above how to call through to the :attr:`__init__` method of the base
836+
We see above how to call through to the :meth:`~object.__init__` method of the base
837837
type.
838838

839839
This pattern is important when writing a type with custom

Doc/howto/descriptor.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,8 @@ by a search through the class's :term:`method resolution order`.
779779

780780
If a descriptor is found, it is invoked with ``desc.__get__(None, A)``.
781781

782-
The full C implementation can be found in :c:func:`type_getattro()` and
783-
:c:func:`_PyType_Lookup()` in :source:`Objects/typeobject.c`.
782+
The full C implementation can be found in :c:func:`!type_getattro` and
783+
:c:func:`!_PyType_Lookup` in :source:`Objects/typeobject.c`.
784784

785785

786786
Invocation from super
@@ -794,7 +794,7 @@ for the base class ``B`` immediately following ``A`` and then returns
794794
``B.__dict__['m'].__get__(obj, A)``. If not a descriptor, ``m`` is returned
795795
unchanged.
796796

797-
The full C implementation can be found in :c:func:`super_getattro()` in
797+
The full C implementation can be found in :c:func:`!super_getattro` in
798798
:source:`Objects/typeobject.c`. A pure Python equivalent can be found in
799799
`Guido's Tutorial
800800
<https://www.python.org/download/releases/2.2.3/descrintro/#cooperation>`_.

Doc/tools/.nitignore

-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ Doc/c-api/sys.rst
2424
Doc/c-api/type.rst
2525
Doc/c-api/typeobj.rst
2626
Doc/c-api/unicode.rst
27-
Doc/extending/embedding.rst
2827
Doc/extending/extending.rst
2928
Doc/extending/newtypes.rst
30-
Doc/extending/newtypes_tutorial.rst
3129
Doc/faq/design.rst
3230
Doc/faq/extending.rst
3331
Doc/faq/gui.rst

Doc/whatsnew/2.5.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -2151,8 +2151,8 @@ Changes to Python's build process and to the C API include:
21512151

21522152
Previously these different families all reduced to the platform's
21532153
:c:func:`malloc` and :c:func:`free` functions. This meant it didn't matter if
2154-
you got things wrong and allocated memory with the :c:func:`PyMem` function but
2155-
freed it with the :c:func:`PyObject` function. With 2.5's changes to obmalloc,
2154+
you got things wrong and allocated memory with the ``PyMem`` function but
2155+
freed it with the ``PyObject`` function. With 2.5's changes to obmalloc,
21562156
these families now do different things and mismatches will probably result in a
21572157
segfault. You should carefully test your C extension modules with Python 2.5.
21582158

Doc/whatsnew/3.8.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1850,7 +1850,7 @@ Changes in Python behavior
18501850
finalizing, making them consistent with :c:func:`PyEval_RestoreThread`,
18511851
:c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`. If this
18521852
behavior is not desired, guard the call by checking :c:func:`_Py_IsFinalizing`
1853-
or :c:func:`sys.is_finalizing`.
1853+
or :func:`sys.is_finalizing`.
18541854
(Contributed by Joannah Nanjekye in :issue:`36475`.)
18551855

18561856

0 commit comments

Comments
 (0)