Skip to content

Commit 3b7c312

Browse files
Fill out the slot typedef descriptions.
1 parent c67b704 commit 3b7c312

File tree

1 file changed

+116
-53
lines changed

1 file changed

+116
-53
lines changed

Doc/c-api/typeobj.rst

+116-53
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
650650
651651
A pointer to the instance destructor function. This function must be defined
652652
unless the type guarantees that its instances will never be deallocated (as is
653-
the case for the singletons ``None`` and ``Ellipsis``).
653+
the case for the singletons ``None`` and ``Ellipsis``). The function signature is::
654+
655+
void tp_dealloc(PyObject *self);
654656

655657
The destructor function is called by the :c:func:`Py_DECREF` and
656658
:c:func:`Py_XDECREF` macros when the new reference count is zero. At this point,
@@ -733,21 +735,27 @@ and :c:type:`PyType_Type` effectively act as defaults.)
733735
An optional pointer to a function that implements the built-in function
734736
:func:`repr`.
735737

736-
The signature is the same as for :c:func:`PyObject_Repr`; it must return a string
737-
or a Unicode object. Ideally, this function should return a string that, when
738-
passed to :func:`eval`, given a suitable environment, returns an object with the
738+
The signature is the same as for :c:func:`PyObject_Repr`::
739+
740+
PyObject *tp_repr(PyObject *self);
741+
742+
The function must return a string or a Unicode object. Ideally,
743+
this function should return a string that, when passed to
744+
:func:`eval`, given a suitable environment, returns an object with the
739745
same value. If this is not feasible, it should return a string starting with
740746
``'<'`` and ending with ``'>'`` from which both the type and the value of the
741747
object can be deduced.
742748

743-
When this field is not set, a string of the form ``<%s object at %p>`` is
744-
returned, where ``%s`` is replaced by the type name, and ``%p`` by the object's
745-
memory address.
746-
747749
**Inheritance:**
748750

749751
This field is inherited by subtypes.
750752

753+
**Default:**
754+
755+
When this field is not set, a string of the form ``<%s object at %p>`` is
756+
returned, where ``%s`` is replaced by the type name, and ``%p`` by the object's
757+
memory address.
758+
751759

752760
.. c:member:: PyNumberMethods* PyTypeObject.tp_as_number
753761
@@ -792,8 +800,11 @@ and :c:type:`PyType_Type` effectively act as defaults.)
792800
An optional pointer to a function that implements the built-in function
793801
:func:`hash`.
794802

795-
The signature is the same as for :c:func:`PyObject_Hash`; it must return a
796-
value of the type Py_hash_t. The value ``-1`` should not be returned as a
803+
The signature is the same as for :c:func:`PyObject_Hash`::
804+
805+
Py_hash_t tp_hash(PyObject *);
806+
807+
The value ``-1`` should not be returned as a
797808
normal return value; when an error occurs during the computation of the hash
798809
value, the function should set an exception and return ``-1``.
799810

@@ -823,7 +834,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
823834
824835
An optional pointer to a function that implements calling the object. This
825836
should be *NULL* if the object is not callable. The signature is the same as
826-
for :c:func:`PyObject_Call`.
837+
for :c:func:`PyObject_Call`::
838+
839+
PyObject *tp_call(PyObject *self, PyObject *args, PyObject *kwargs);
827840

828841
**Inheritance:**
829842

@@ -837,26 +850,34 @@ and :c:type:`PyType_Type` effectively act as defaults.)
837850
constructor for that type. This constructor calls :c:func:`PyObject_Str` to do
838851
the actual work, and :c:func:`PyObject_Str` will call this handler.)
839852

840-
The signature is the same as for :c:func:`PyObject_Str`; it must return a string
841-
or a Unicode object. This function should return a "friendly" string
853+
The signature is the same as for :c:func:`PyObject_Str`::
854+
855+
PyObject *tp_str(PyObject *self);
856+
857+
The function must return a string or a Unicode object. It should be a "friendly" string
842858
representation of the object, as this is the representation that will be used,
843859
among other things, by the :func:`print` function.
844860

845-
When this field is not set, :c:func:`PyObject_Repr` is called to return a string
846-
representation.
847-
848861
**Inheritance:**
849862

850863
This field is inherited by subtypes.
851864

865+
**Default:**
866+
867+
When this field is not set, :c:func:`PyObject_Repr` is called to return a string
868+
representation.
869+
852870

853871
.. c:member:: getattrofunc PyTypeObject.tp_getattro
854872
855873
An optional pointer to the get-attribute function.
856874

857-
The signature is the same as for :c:func:`PyObject_GetAttr`. It is usually
858-
convenient to set this field to :c:func:`PyObject_GenericGetAttr`, which
859-
implements the normal way of looking for object attributes.
875+
The signature is the same as for :c:func:`PyObject_GetAttr`::
876+
877+
PyObject *tp_getattro(PyObject *self, PyObject *attr);
878+
879+
It is usually convenient to set this field to :c:func:`PyObject_GenericGetAttr`,
880+
which implements the normal way of looking for object attributes.
860881

861882
**Inheritance:**
862883

@@ -875,10 +896,14 @@ and :c:type:`PyType_Type` effectively act as defaults.)
875896
876897
An optional pointer to the function for setting and deleting attributes.
877898

878-
The signature is the same as for :c:func:`PyObject_SetAttr`, but setting
879-
*v* to *NULL* to delete an attribute must be supported. It is usually
880-
convenient to set this field to :c:func:`PyObject_GenericSetAttr`, which
881-
implements the normal way of setting object attributes.
899+
The signature is the same as for :c:func:`PyObject_SetAttr`::
900+
901+
PyObject *tp_setattro(PyObject *self, PyObject *attr, PyObject *value);
902+
903+
In addition, setting *value* to *NULL* to delete an attribute must be
904+
supported. It is usually convenient to set this field to
905+
:c:func:`PyObject_GenericSetAttr`, which implements the normal
906+
way of setting object attributes.
882907

883908
**Inheritance:**
884909

@@ -1062,9 +1087,12 @@ and :c:type:`PyType_Type` effectively act as defaults.)
10621087
.. c:member:: traverseproc PyTypeObject.tp_traverse
10631088
10641089
An optional pointer to a traversal function for the garbage collector. This is
1065-
only used if the :const:`Py_TPFLAGS_HAVE_GC` flag bit is set. More information
1066-
about Python's garbage collection scheme can be found in section
1067-
:ref:`supporting-cycle-detection`.
1090+
only used if the :const:`Py_TPFLAGS_HAVE_GC` flag bit is set. The signature is::
1091+
1092+
int tp_traverse(PyObject *self, visitproc visit, void *arg);
1093+
1094+
More information about Python's garbage collection scheme can be found
1095+
in section :ref:`supporting-cycle-detection`.
10681096

10691097
The :c:member:`~PyTypeObject.tp_traverse` pointer is used by the garbage collector to detect
10701098
reference cycles. A typical implementation of a :c:member:`~PyTypeObject.tp_traverse` function
@@ -1106,7 +1134,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
11061134
.. c:member:: inquiry PyTypeObject.tp_clear
11071135
11081136
An optional pointer to a clear function for the garbage collector. This is only
1109-
used if the :const:`Py_TPFLAGS_HAVE_GC` flag bit is set.
1137+
used if the :const:`Py_TPFLAGS_HAVE_GC` flag bit is set. The signature is::
1138+
1139+
int tp_clear(PyObject *);
11101140

11111141
The :c:member:`~PyTypeObject.tp_clear` member function is used to break reference cycles in cyclic
11121142
garbage detected by the garbage collector. Taken together, all :c:member:`~PyTypeObject.tp_clear`
@@ -1164,10 +1194,12 @@ and :c:type:`PyType_Type` effectively act as defaults.)
11641194

11651195
.. c:member:: richcmpfunc PyTypeObject.tp_richcompare
11661196
1167-
An optional pointer to the rich comparison function, whose signature is
1168-
``PyObject *tp_richcompare(PyObject *a, PyObject *b, int op)``. The first
1169-
parameter is guaranteed to be an instance of the type that is defined
1170-
by :c:type:`PyTypeObject`.
1197+
An optional pointer to the rich comparison function, whose signature is::
1198+
1199+
PyObject *tp_richcompare(PyObject *self, PyObject *other, int op);
1200+
1201+
The first parameter is guaranteed to be an instance of the type
1202+
that is defined by :c:type:`PyTypeObject`.
11711203

11721204
The function should return the result of the comparison (usually ``Py_True``
11731205
or ``Py_False``). If the comparison is undefined, it must return
@@ -1272,7 +1304,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
12721304
presence normally signals that the instances of this type are iterable (although
12731305
sequences may be iterable without this function).
12741306

1275-
This function has the same signature as :c:func:`PyObject_GetIter`.
1307+
This function has the same signature as :c:func:`PyObject_GetIter`::
1308+
1309+
PyObject *tp_iter(PyObject *self);
12761310

12771311
**Inheritance:**
12781312

@@ -1282,6 +1316,10 @@ and :c:type:`PyType_Type` effectively act as defaults.)
12821316
.. c:member:: iternextfunc PyTypeObject.tp_iternext
12831317
12841318
An optional pointer to a function that returns the next item in an iterator.
1319+
The signature is::
1320+
1321+
PyObject *tp_iternext(PyObject *self);
1322+
12851323
When the iterator is exhausted, it must return *NULL*; a :exc:`StopIteration`
12861324
exception may or may not be set. When another error occurs, it must return
12871325
*NULL* too. Its presence signals that the instances of this type are
@@ -1387,11 +1425,11 @@ and :c:type:`PyType_Type` effectively act as defaults.)
13871425
13881426
An optional pointer to a "descriptor get" function.
13891427

1390-
The function signature is ::
1428+
The function signature is::
13911429

13921430
PyObject * tp_descr_get(PyObject *self, PyObject *obj, PyObject *type);
13931431

1394-
.. XXX explain.
1432+
.. XXX explain more?
13951433
13961434
**Inheritance:**
13971435

@@ -1403,13 +1441,13 @@ and :c:type:`PyType_Type` effectively act as defaults.)
14031441
An optional pointer to a function for setting and deleting
14041442
a descriptor's value.
14051443

1406-
The function signature is ::
1444+
The function signature is::
14071445

14081446
int tp_descr_set(PyObject *self, PyObject *obj, PyObject *value);
14091447

14101448
The *value* argument is set to *NULL* to delete the value.
14111449

1412-
.. XXX explain.
1450+
.. XXX explain more?
14131451
14141452
**Inheritance:**
14151453

@@ -1485,9 +1523,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
14851523
:meth:`__init__`, and it is possible to reinitialize an instance by calling its
14861524
:meth:`__init__` method again.
14871525

1488-
The function signature is ::
1526+
The function signature is::
14891527

1490-
int tp_init(PyObject *self, PyObject *args, PyObject *kwds)
1528+
int tp_init(PyObject *self, PyObject *args, PyObject *kwds);
14911529

14921530
The self argument is the instance to be initialized; the *args* and *kwds*
14931531
arguments represent positional and keyword arguments of the call to
@@ -1513,9 +1551,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
15131551
15141552
An optional pointer to an instance allocation function.
15151553

1516-
The function signature is ::
1554+
The function signature is::
15171555

1518-
PyObject *tp_alloc(PyTypeObject *self, Py_ssize_t nitems)
1556+
PyObject *tp_alloc(PyTypeObject *self, Py_ssize_t nitems);
15191557

15201558
**Inheritance:**
15211559

@@ -1537,9 +1575,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
15371575
15381576
An optional pointer to an instance creation function.
15391577

1540-
The function signature is ::
1578+
The function signature is::
15411579

1542-
PyObject *tp_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
1580+
PyObject *tp_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds);
15431581

15441582
The subtype argument is the type of the object being created; the *args* and
15451583
*kwds* arguments represent positional and keyword arguments of the call to the
@@ -1568,12 +1606,11 @@ and :c:type:`PyType_Type` effectively act as defaults.)
15681606
instances, like a factory function.
15691607

15701608

1571-
.. c:member:: destructor PyTypeObject.tp_free
1609+
.. c:member:: freefunc PyTypeObject.tp_free
15721610
1573-
An optional pointer to an instance deallocation function. Its signature is
1574-
:c:type:`freefunc`::
1611+
An optional pointer to an instance deallocation function. Its signature is::
15751612

1576-
void tp_free(void *)
1613+
void tp_free(void *self);
15771614

15781615
An initializer that is compatible with this signature is :c:func:`PyObject_Free`.
15791616

@@ -1601,9 +1638,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
16011638
some types have a mixture of statically and dynamically allocated instances, and
16021639
the statically allocated instances are not collectible. Such types should
16031640
define this function; it should return ``1`` for a collectible instance, and
1604-
``0`` for a non-collectible instance. The signature is ::
1641+
``0`` for a non-collectible instance. The signature is::
16051642

1606-
int tp_is_gc(PyObject *self)
1643+
int tp_is_gc(PyObject *self);
16071644

16081645
(The only example of this are types themselves. The metatype,
16091646
:c:data:`PyType_Type`, defines this function to distinguish between statically
@@ -1689,7 +1726,7 @@ and :c:type:`PyType_Type` effectively act as defaults.)
16891726
16901727
An optional pointer to an instance finalization function. Its signature is::
16911728

1692-
void tp_finalize(PyObject *self)
1729+
void tp_finalize(PyObject *self);
16931730

16941731
If :c:member:`~PyTypeObject.tp_finalize` is set, the interpreter calls it once when
16951732
finalizing an instance. It is called either from the garbage
@@ -2115,7 +2152,7 @@ Async Object Structures
21152152
21162153
The signature of this function is::
21172154

2118-
PyObject *am_await(PyObject *self)
2155+
PyObject *am_await(PyObject *self);
21192156

21202157
The returned object must be an iterator, i.e. :c:func:`PyIter_Check` must
21212158
return ``1`` for it.
@@ -2126,7 +2163,7 @@ Async Object Structures
21262163
21272164
The signature of this function is::
21282165

2129-
PyObject *am_aiter(PyObject *self)
2166+
PyObject *am_aiter(PyObject *self);
21302167

21312168
Must return an :term:`awaitable` object. See :meth:`__anext__` for details.
21322169

@@ -2137,7 +2174,7 @@ Async Object Structures
21372174
21382175
The signature of this function is::
21392176

2140-
PyObject *am_anext(PyObject *self)
2177+
PyObject *am_anext(PyObject *self);
21412178

21422179
Must return an :term:`awaitable` object. See :meth:`__anext__` for details.
21432180
This slot may be set to *NULL*.
@@ -2165,16 +2202,26 @@ Slot Type typedefs
21652202

21662203
.. c:type:: void (*destructor)(PyObject *)
21672204
2168-
.. c:type:: void (*freefunc)(void)
2205+
.. c:type:: void (*freefunc)(void *)
2206+
2207+
See :c:member:`~PyTypeObject.tp_free`.
21692208

21702209
.. c:type:: PyObject *(*newfunc)(PyObject *, PyObject *, PyObject *)
21712210
2211+
See :c:member:`~PyTypeObject.tp_new`.
2212+
21722213
.. c:type:: int (*initproc)(PyObject *, PyObject *, PyObject *)
21732214
2215+
See :c:member:`~PyTypeObject.tp_init`.
2216+
21742217
.. c:type:: PyObject *(*reprfunc)(PyObject *)
21752218
2219+
See :c:member:`~PyTypeObject.tp_repr`.
2220+
21762221
.. c:type:: int (*printfunc)(PyObject *, FILE *, int)
21772222
2223+
This is hidden if :const:`PY_LIMITED_API` is set.
2224+
21782225
.. c:type:: PyObject *(*getattrfunc)(PyObject *self, char *attr)
21792226
21802227
Return the value of the named attribute for the object.
@@ -2188,23 +2235,39 @@ Slot Type typedefs
21882235
21892236
Return the value of the named attribute for the object.
21902237

2238+
See :c:member:`~PyTypeObject.tp_getattro`.
2239+
21912240
.. c:type:: int (*setattrofunc)(PyObject *self, PyObject *attr, PyObject *value)
21922241
21932242
Set the value of the named attribute for the object.
21942243
The value argument is set to *NULL* to delete the attribute.
21952244

2245+
See :c:member:`~PyTypeObject.tp_setattro`.
2246+
21962247
.. c:type:: PyObject *(*descrgetfunc)(PyObject *, PyObject *, PyObject *)
21972248
2249+
See :c:member:`~PyTypeObject.tp_descrget`.
2250+
21982251
.. c:type:: int (*descrsetfunc)(PyObject *, PyObject *, PyObject *)
21992252
2253+
See :c:member:`~PyTypeObject.tp_descrset`.
2254+
22002255
.. c:type:: Py_hash_t (*hashfunc)(PyObject *)
22012256
2257+
See :c:member:`~PyTypeObject.tp_hash`.
2258+
22022259
.. c:type:: PyObject *(*richcmpfunc)(PyObject *, PyObject *, int)
22032260
2261+
See :c:member:`~PyTypeObject.tp_richcompare`.
2262+
22042263
.. c:type:: PyObject *(*getiterfunc)(PyObject *)
22052264
2265+
See :c:member:`~PyTypeObject.tp_iter`.
2266+
22062267
.. c:type:: PyObject *(*iternextfunc)(PyObject *)
22072268
2269+
See :c:member:`~PyTypeObject.tp_iternext`.
2270+
22082271
.. c:type:: Py_ssize_t (*lenfunc)(PyObject *)
22092272
22102273
.. c:type:: int (*getbufferproc)(PyObject *, Py_buffer *, int)

0 commit comments

Comments
 (0)