@@ -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
166166To 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
168168has to be specified explicitly. In this case, we can just use the default
169169implementation provided by the API function :c:func: `PyType_GenericNew `. ::
170170
171171 .tp_new = PyType_GenericNew,
172172
173173Everything 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
218218doesn'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
271271calls 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
274274be 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
311311The ``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.
313313It is not required to define a ``tp_new `` member, and indeed many extension
314314types will simply reuse :c:func: `PyType_GenericNew ` as done in the first
315315version 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
388388The :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
390390created. Initializers always accept positional and keyword arguments,
391391and they should return either ``0 `` on success or ``-1 `` on error.
392392
393393Unlike the ``tp_new `` handler, there is no guarantee that ``tp_init ``
394394is 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
397397our objects. For this reason, we have to be extra careful when assigning
398398the 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
708708For 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
712712returned 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
789789easily use the :c:type: `PyTypeObject ` it needs. It can be difficult to share
790790these :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
793793built-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
795795increases 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
821821object structure must be the first value. The base type will already include
822822the :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
825825can 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
837837type.
838838
839839This pattern is important when writing a type with custom
0 commit comments