Skip to content

Commit d363eb5

Browse files
gh-107091: Fix some uses of :attr: role (GH-107318)
Fix also formatting of PyMethodDef members.
1 parent 8d61a71 commit d363eb5

File tree

11 files changed

+64
-59
lines changed

11 files changed

+64
-59
lines changed

Doc/c-api/import.rst

+11-9
Original file line numberDiff line numberDiff line change
@@ -310,23 +310,25 @@ Importing Modules
310310
311311
.. c:struct:: _inittab
312312
313-
Structure describing a single entry in the list of built-in modules. Each of
314-
these structures gives the name and initialization function for a module built
315-
into the interpreter. The name is an ASCII encoded string. Programs which
313+
Structure describing a single entry in the list of built-in modules.
314+
Programs which
316315
embed Python may use an array of these structures in conjunction with
317316
:c:func:`PyImport_ExtendInittab` to provide additional built-in modules.
318-
The structure is defined in :file:`Include/import.h` as::
317+
The structure consists of two members:
319318
320-
struct _inittab {
321-
const char *name; /* ASCII encoded string */
322-
PyObject* (*initfunc)(void);
323-
};
319+
.. c:member:: const char *name
320+
321+
The module name, as an ASCII encoded string.
322+
323+
.. c: member:: PyObject* (*initfunc)(void)
324+
325+
Initialization function for a module built into the interpreter.
324326
325327
326328
.. c:function:: int PyImport_ExtendInittab(struct _inittab *newtab)
327329
328330
Add a collection of modules to the table of built-in modules. The *newtab*
329-
array must end with a sentinel entry which contains ``NULL`` for the :attr:`name`
331+
array must end with a sentinel entry which contains ``NULL`` for the :c:member:`~_inittab.name`
330332
field; failure to provide the sentinel value can result in a memory fault.
331333
Returns ``0`` on success or ``-1`` if insufficient memory could be allocated to
332334
extend the internal table. In the event of failure, no modules are added to the

Doc/c-api/init.rst

+5-2
Original file line numberDiff line numberDiff line change
@@ -827,8 +827,11 @@ code, or when embedding the Python interpreter:
827827
.. c:type:: PyThreadState
828828
829829
This data structure represents the state of a single thread. The only public
830-
data member is :attr:`interp` (:c:expr:`PyInterpreterState *`), which points to
831-
this thread's interpreter state.
830+
data member is:
831+
832+
.. c:member:: PyInterpreterState *interp
833+
834+
This thread's interpreter state.
832835
833836
834837
.. c:function:: PyThreadState* PyEval_SaveThread()

Doc/c-api/structures.rst

+8-8
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ under :ref:`reference counting <countingrefs>`.
3535

3636
.. c:type:: PyVarObject
3737
38-
This is an extension of :c:type:`PyObject` that adds the :attr:`ob_size`
38+
This is an extension of :c:type:`PyObject` that adds the :c:member:`~PyVarObject.ob_size`
3939
field. This is only used for objects that have some notion of *length*.
4040
This type does not often appear in the Python/C API.
4141
Access to the members must be done by using the macros
@@ -152,7 +152,7 @@ under :ref:`reference counting <countingrefs>`.
152152
.. c:macro:: PyVarObject_HEAD_INIT(type, size)
153153
154154
This is a macro which expands to initialization values for a new
155-
:c:type:`PyVarObject` type, including the :attr:`ob_size` field.
155+
:c:type:`PyVarObject` type, including the :c:member:`~PyVarObject.ob_size` field.
156156
This macro expands to::
157157
158158
_PyObject_EXTRA_INIT
@@ -228,21 +228,21 @@ Implementing functions and methods
228228
Structure used to describe a method of an extension type. This structure has
229229
four fields:
230230
231-
.. c:member:: const char* ml_name
231+
.. c:member:: const char *ml_name
232232
233-
name of the method
233+
Name of the method.
234234
235235
.. c:member:: PyCFunction ml_meth
236236
237-
pointer to the C implementation
237+
Pointer to the C implementation.
238238
239239
.. c:member:: int ml_flags
240240
241-
flags bits indicating how the call should be constructed
241+
Flags bits indicating how the call should be constructed.
242242
243-
.. c:member:: const char* ml_doc
243+
.. c:member:: const char *ml_doc
244244
245-
points to the contents of the docstring
245+
Points to the contents of the docstring.
246246
247247
The :c:member:`~PyMethodDef.ml_meth` is a C function pointer.
248248
The functions may be of different

Doc/c-api/tuple.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ type.
167167
168168
Describes a field of a struct sequence. As a struct sequence is modeled as a
169169
tuple, all fields are typed as :c:expr:`PyObject*`. The index in the
170-
:attr:`fields` array of the :c:type:`PyStructSequence_Desc` determines which
170+
:c:member:`~PyStructSequence_Desc.fields` array of
171+
the :c:type:`PyStructSequence_Desc` determines which
171172
field of the struct sequence is described.
172173
173174
+-----------+------------------+-----------------------------------------+

Doc/c-api/typeobj.rst

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

487487
The type object structure extends the :c:type:`PyVarObject` structure. The
488-
:attr:`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 :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.
491-
type objects) *must* have the :attr:`ob_size` field.
491+
type objects) *must* have the :c:member:`~PyVarObject.ob_size` field.
492492

493493

494494
.. c:member:: Py_ssize_t PyObject.ob_refcnt
495495
496496
This is the type object's reference count, initialized to ``1`` by the
497497
``PyObject_HEAD_INIT`` macro. Note that for :ref:`statically allocated type
498-
objects <static-types>`, the type's instances (objects whose :attr:`ob_type`
498+
objects <static-types>`, the type's instances (objects whose :c:member:`~PyObject.ob_type`
499499
points back to the type) do *not* count as references. But for
500500
:ref:`dynamically allocated type objects <heap-types>`, the instances *do*
501501
count as references.
@@ -519,8 +519,8 @@ type objects) *must* have the :attr:`ob_size` field.
519519
Foo_Type.ob_type = &PyType_Type;
520520

521521
This should be done before any instances of the type are created.
522-
:c:func:`PyType_Ready` checks if :attr:`ob_type` is ``NULL``, and if so,
523-
initializes it to the :attr:`ob_type` field of the base class.
522+
:c:func:`PyType_Ready` checks if :c:member:`~PyObject.ob_type` is ``NULL``, and if so,
523+
initializes it to the :c:member:`~PyObject.ob_type` field of the base class.
524524
:c:func:`PyType_Ready` will not change this field if it is non-zero.
525525

526526
**Inheritance:**
@@ -619,20 +619,20 @@ and :c:data:`PyType_Type` effectively act as defaults.)
619619
instances have the same size, given in :c:member:`~PyTypeObject.tp_basicsize`.
620620

621621
For a type with variable-length instances, the instances must have an
622-
:attr:`ob_size` field, and the instance size is :c:member:`~PyTypeObject.tp_basicsize` plus N
622+
:c:member:`~PyVarObject.ob_size` field, and the instance size is :c:member:`~PyTypeObject.tp_basicsize` plus N
623623
times :c:member:`~PyTypeObject.tp_itemsize`, where N is the "length" of the object. The value of
624-
N is typically stored in the instance's :attr:`ob_size` field. There are
625-
exceptions: for example, ints use a negative :attr:`ob_size` to indicate a
624+
N is typically stored in the instance's :c:member:`~PyVarObject.ob_size` field. There are
625+
exceptions: for example, ints use a negative :c:member:`~PyVarObject.ob_size` to indicate a
626626
negative number, and N is ``abs(ob_size)`` there. Also, the presence of an
627-
:attr:`ob_size` field in the instance layout doesn't mean that the instance
627+
:c:member:`~PyVarObject.ob_size` field in the instance layout doesn't mean that the instance
628628
structure is variable-length (for example, the structure for the list type has
629-
fixed-length instances, yet those instances have a meaningful :attr:`ob_size`
629+
fixed-length instances, yet those instances have a meaningful :c:member:`~PyVarObject.ob_size`
630630
field).
631631

632632
The basic size includes the fields in the instance declared by the macro
633633
:c:macro:`PyObject_HEAD` or :c:macro:`PyObject_VAR_HEAD` (whichever is used to
634-
declare the instance struct) and this in turn includes the :attr:`_ob_prev` and
635-
:attr:`_ob_next` fields if they are present. This means that the only correct
634+
declare the instance struct) and this in turn includes the :c:member:`~PyObject._ob_prev` and
635+
:c:member:`~PyObject._ob_next` fields if they are present. This means that the only correct
636636
way to get an initializer for the :c:member:`~PyTypeObject.tp_basicsize` is to use the
637637
``sizeof`` operator on the struct used to declare the instance layout.
638638
The basic size does not include the GC header size.
@@ -764,7 +764,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
764764

765765
**Inheritance:**
766766

767-
Group: :attr:`tp_getattr`, :attr:`tp_getattro`
767+
Group: :c:member:`~PyTypeObject.tp_getattr`, :c:member:`~PyTypeObject.tp_getattro`
768768

769769
This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_getattro`: a subtype
770770
inherits both :c:member:`~PyTypeObject.tp_getattr` and :c:member:`~PyTypeObject.tp_getattro` from its base type when
@@ -781,7 +781,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
781781

782782
**Inheritance:**
783783

784-
Group: :attr:`tp_setattr`, :attr:`tp_setattro`
784+
Group: :c:member:`~PyTypeObject.tp_setattr`, :c:member:`~PyTypeObject.tp_setattro`
785785

786786
This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_setattro`: a subtype
787787
inherits both :c:member:`~PyTypeObject.tp_setattr` and :c:member:`~PyTypeObject.tp_setattro` from its base type when
@@ -883,7 +883,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
883883
normal return value; when an error occurs during the computation of the hash
884884
value, the function should set an exception and return ``-1``.
885885

886-
When this field is not set (*and* :attr:`tp_richcompare` is not set),
886+
When this field is not set (*and* :c:member:`~PyTypeObject.tp_richcompare` is not set),
887887
an attempt to take the hash of the object raises :exc:`TypeError`.
888888
This is the same as setting it to :c:func:`PyObject_HashNotImplemented`.
889889

@@ -897,7 +897,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
897897

898898
**Inheritance:**
899899

900-
Group: :attr:`tp_hash`, :attr:`tp_richcompare`
900+
Group: :c:member:`~PyTypeObject.tp_hash`, :c:member:`~PyTypeObject.tp_richcompare`
901901

902902
This field is inherited by subtypes together with
903903
:c:member:`~PyTypeObject.tp_richcompare`: a subtype inherits both of
@@ -956,7 +956,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
956956

957957
**Inheritance:**
958958

959-
Group: :attr:`tp_getattr`, :attr:`tp_getattro`
959+
Group: :c:member:`~PyTypeObject.tp_getattr`, :c:member:`~PyTypeObject.tp_getattro`
960960

961961
This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_getattr`: a subtype
962962
inherits both :c:member:`~PyTypeObject.tp_getattr` and :c:member:`~PyTypeObject.tp_getattro` from its base type when
@@ -982,7 +982,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
982982

983983
**Inheritance:**
984984

985-
Group: :attr:`tp_setattr`, :attr:`tp_setattro`
985+
Group: :c:member:`~PyTypeObject.tp_setattr`, :c:member:`~PyTypeObject.tp_setattro`
986986

987987
This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_setattr`: a subtype
988988
inherits both :c:member:`~PyTypeObject.tp_setattr` and :c:member:`~PyTypeObject.tp_setattro` from its base type when
@@ -1047,7 +1047,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
10471047
10481048
This bit is set when the type object itself is allocated on the heap, for
10491049
example, types created dynamically using :c:func:`PyType_FromSpec`. In this
1050-
case, the :attr:`ob_type` field of its instances is considered a reference to
1050+
case, the :c:member:`~PyObject.ob_type` field of its instances is considered a reference to
10511051
the type, and the type object is INCREF'ed when a new instance is created, and
10521052
DECREF'ed when an instance is destroyed (this does not apply to instances of
10531053
subtypes; only the type referenced by the instance's ob_type gets INCREF'ed or
@@ -1100,13 +1100,13 @@ and :c:data:`PyType_Type` effectively act as defaults.)
11001100

11011101
**Inheritance:**
11021102

1103-
Group: :c:macro:`Py_TPFLAGS_HAVE_GC`, :attr:`tp_traverse`, :attr:`tp_clear`
1103+
Group: :c:macro:`Py_TPFLAGS_HAVE_GC`, :c:member:`~PyTypeObject.tp_traverse`, :c:member:`~PyTypeObject.tp_clear`
11041104

11051105
The :c:macro:`Py_TPFLAGS_HAVE_GC` flag bit is inherited
1106-
together with the :attr:`tp_traverse` and :attr:`tp_clear`
1106+
together with the :c:member:`~PyTypeObject.tp_traverse` and :c:member:`~PyTypeObject.tp_clear`
11071107
fields, i.e. if the :c:macro:`Py_TPFLAGS_HAVE_GC` flag bit is
1108-
clear in the subtype and the :attr:`tp_traverse` and
1109-
:attr:`tp_clear` fields in the subtype exist and have ``NULL``
1108+
clear in the subtype and the :c:member:`~PyTypeObject.tp_traverse` and
1109+
:c:member:`~PyTypeObject.tp_clear` fields in the subtype exist and have ``NULL``
11101110
values.
11111111

11121112

@@ -1421,7 +1421,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
14211421

14221422
**Inheritance:**
14231423

1424-
Group: :c:macro:`Py_TPFLAGS_HAVE_GC`, :attr:`tp_traverse`, :attr:`tp_clear`
1424+
Group: :c:macro:`Py_TPFLAGS_HAVE_GC`, :c:member:`~PyTypeObject.tp_traverse`, :c:member:`~PyTypeObject.tp_clear`
14251425

14261426
This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_clear` and the
14271427
:c:macro:`Py_TPFLAGS_HAVE_GC` flag bit: the flag bit, :c:member:`~PyTypeObject.tp_traverse`, and
@@ -1488,7 +1488,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
14881488

14891489
**Inheritance:**
14901490

1491-
Group: :c:macro:`Py_TPFLAGS_HAVE_GC`, :attr:`tp_traverse`, :attr:`tp_clear`
1491+
Group: :c:macro:`Py_TPFLAGS_HAVE_GC`, :c:member:`~PyTypeObject.tp_traverse`, :c:member:`~PyTypeObject.tp_clear`
14921492

14931493
This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_traverse` and the
14941494
:c:macro:`Py_TPFLAGS_HAVE_GC` flag bit: the flag bit, :c:member:`~PyTypeObject.tp_traverse`, and
@@ -1547,7 +1547,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
15471547

15481548
**Inheritance:**
15491549

1550-
Group: :attr:`tp_hash`, :attr:`tp_richcompare`
1550+
Group: :c:member:`~PyTypeObject.tp_hash`, :c:member:`~PyTypeObject.tp_richcompare`
15511551

15521552
This field is inherited by subtypes together with :c:member:`~PyTypeObject.tp_hash`:
15531553
a subtype inherits :c:member:`~PyTypeObject.tp_richcompare` and :c:member:`~PyTypeObject.tp_hash` when
@@ -1556,9 +1556,9 @@ and :c:data:`PyType_Type` effectively act as defaults.)
15561556

15571557
**Default:**
15581558

1559-
:c:data:`PyBaseObject_Type` provides a :attr:`tp_richcompare`
1559+
:c:data:`PyBaseObject_Type` provides a :c:member:`~PyTypeObject.tp_richcompare`
15601560
implementation, which may be inherited. However, if only
1561-
:attr:`tp_hash` is defined, not even the inherited function is used
1561+
:c:member:`~PyTypeObject.tp_hash` is defined, not even the inherited function is used
15621562
and instances of the type will not be able to participate in any
15631563
comparisons.
15641564

@@ -2374,9 +2374,9 @@ Sequence Object Structures
23742374
This slot must be filled for the :c:func:`PySequence_Check`
23752375
function to return ``1``, it can be ``NULL`` otherwise.
23762376

2377-
Negative indexes are handled as follows: if the :attr:`sq_length` slot is
2377+
Negative indexes are handled as follows: if the :c:member:`~PySequenceMethods.sq_length` slot is
23782378
filled, it is called and the sequence length is used to compute a positive
2379-
index which is passed to :attr:`sq_item`. If :attr:`sq_length` is ``NULL``,
2379+
index which is passed to :c:member:`~PySequenceMethods.sq_item`. If :c:member:`!sq_length` is ``NULL``,
23802380
the index is passed as is to the function.
23812381

23822382
.. c:member:: ssizeobjargproc PySequenceMethods.sq_ass_item
@@ -2586,8 +2586,8 @@ Slot Type typedefs
25862586
The purpose of this function is to separate memory allocation from memory
25872587
initialization. It should return a pointer to a block of memory of adequate
25882588
length for the instance, suitably aligned, and initialized to zeros, but with
2589-
:attr:`ob_refcnt` set to ``1`` and :attr:`ob_type` set to the type argument. If
2590-
the type's :c:member:`~PyTypeObject.tp_itemsize` is non-zero, the object's :attr:`ob_size` field
2589+
:c:member:`~PyObject.ob_refcnt` set to ``1`` and :c:member:`~PyObject.ob_type` set to the type argument. If
2590+
the type's :c:member:`~PyTypeObject.tp_itemsize` is non-zero, the object's :c:member:`~PyVarObject.ob_size` field
25912591
should be initialized to *nitems* and the length of the allocated memory block
25922592
should be ``tp_basicsize + nitems*tp_itemsize``, rounded up to a multiple of
25932593
``sizeof(void*)``; otherwise, *nitems* is not used and the length of the block

Doc/c-api/veryhigh.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ the same library that the Python runtime is using.
353353
executed, it is passed as ``PyCompilerFlags *flags``. In this case, ``from
354354
__future__ import`` can modify *flags*.
355355
356-
Whenever ``PyCompilerFlags *flags`` is ``NULL``, :c:member:`cf_flags` is treated as
356+
Whenever ``PyCompilerFlags *flags`` is ``NULL``, :c:member:`~PyCompilerFlags.cf_flags` is treated as
357357
equal to ``0``, and any modification due to ``from __future__ import`` is
358358
discarded.
359359
@@ -367,7 +367,7 @@ the same library that the Python runtime is using.
367367
initialized to ``PY_MINOR_VERSION``.
368368
369369
The field is ignored by default, it is used if and only if
370-
``PyCF_ONLY_AST`` flag is set in *cf_flags*.
370+
``PyCF_ONLY_AST`` flag is set in :c:member:`~PyCompilerFlags.cf_flags`.
371371
372372
.. versionchanged:: 3.8
373373
Added *cf_feature_version* field.

Doc/extending/newtypes.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ structure::
270270
One entry should be defined for each method provided by the type; no entries are
271271
needed for methods inherited from a base type. One additional entry is needed
272272
at the end; it is a sentinel that marks the end of the array. The
273-
:attr:`ml_name` field of the sentinel must be ``NULL``.
273+
:c:member:`~PyMethodDef.ml_name` field of the sentinel must be ``NULL``.
274274

275275
The second table is used to define attributes which map directly to data stored
276276
in the instance. A variety of primitive C types are supported, and access may

Doc/extending/newtypes_tutorial.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Everything else in the file should be familiar, except for some code in
177177
return;
178178

179179
This initializes the :class:`!Custom` type, filling in a number of members
180-
to the appropriate default values, including :attr:`ob_type` that we initially
180+
to the appropriate default values, including :c:member:`~PyObject.ob_type` that we initially
181181
set to ``NULL``. ::
182182

183183
if (PyModule_AddObjectRef(m, "Custom", (PyObject *) &CustomType) < 0) {

Doc/tools/.nitignore

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Doc/c-api/exceptions.rst
1111
Doc/c-api/file.rst
1212
Doc/c-api/float.rst
1313
Doc/c-api/gcsupport.rst
14-
Doc/c-api/import.rst
1514
Doc/c-api/init.rst
1615
Doc/c-api/init_config.rst
1716
Doc/c-api/intro.rst

Doc/whatsnew/2.5.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ The return value must be either a Python integer or long integer. The
954954
interpreter will check that the type returned is correct, and raises a
955955
:exc:`TypeError` if this requirement isn't met.
956956

957-
A corresponding :attr:`nb_index` slot was added to the C-level
957+
A corresponding :c:member:`~PyNumberMethods.nb_index` slot was added to the C-level
958958
:c:type:`PyNumberMethods` structure to let C extensions implement this protocol.
959959
``PyNumber_Index(obj)`` can be used in extension code to call the
960960
:meth:`__index__` function and retrieve its result.
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
Fix :func:`super` calls on types with custom :attr:`tp_getattro`
1+
Fix :func:`super` calls on types with custom :c:member:`~PyTypeObject.tp_getattro`
22
implementation (e.g. meta-types.)

0 commit comments

Comments
 (0)