@@ -650,7 +650,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
650
650
651
651
A pointer to the instance destructor function. This function must be defined
652
652
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);
654
656
655
657
The destructor function is called by the :c:func: `Py_DECREF ` and
656
658
: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.)
733
735
An optional pointer to a function that implements the built-in function
734
736
:func: `repr `.
735
737
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
739
745
same value. If this is not feasible, it should return a string starting with
740
746
``'<' `` and ending with ``'>' `` from which both the type and the value of the
741
747
object can be deduced.
742
748
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
-
747
749
**Inheritance: **
748
750
749
751
This field is inherited by subtypes.
750
752
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
+
751
759
752
760
.. c :member :: PyNumberMethods* PyTypeObject.tp_as_number
753
761
@@ -792,8 +800,11 @@ and :c:type:`PyType_Type` effectively act as defaults.)
792
800
An optional pointer to a function that implements the built-in function
793
801
:func: `hash `.
794
802
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
797
808
normal return value; when an error occurs during the computation of the hash
798
809
value, the function should set an exception and return ``-1 ``.
799
810
@@ -823,7 +834,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
823
834
824
835
An optional pointer to a function that implements calling the object. This
825
836
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);
827
840
828
841
**Inheritance: **
829
842
@@ -837,26 +850,34 @@ and :c:type:`PyType_Type` effectively act as defaults.)
837
850
constructor for that type. This constructor calls :c:func: `PyObject_Str ` to do
838
851
the actual work, and :c:func: `PyObject_Str ` will call this handler.)
839
852
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
842
858
representation of the object, as this is the representation that will be used,
843
859
among other things, by the :func: `print ` function.
844
860
845
- When this field is not set, :c:func: `PyObject_Repr ` is called to return a string
846
- representation.
847
-
848
861
**Inheritance: **
849
862
850
863
This field is inherited by subtypes.
851
864
865
+ **Default: **
866
+
867
+ When this field is not set, :c:func: `PyObject_Repr ` is called to return a string
868
+ representation.
869
+
852
870
853
871
.. c :member :: getattrofunc PyTypeObject.tp_getattro
854
872
855
873
An optional pointer to the get-attribute function.
856
874
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.
860
881
861
882
**Inheritance: **
862
883
@@ -875,10 +896,14 @@ and :c:type:`PyType_Type` effectively act as defaults.)
875
896
876
897
An optional pointer to the function for setting and deleting attributes.
877
898
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.
882
907
883
908
**Inheritance: **
884
909
@@ -1062,9 +1087,12 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1062
1087
.. c :member :: traverseproc PyTypeObject.tp_traverse
1063
1088
1064
1089
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 `.
1068
1096
1069
1097
The :c:member: `~PyTypeObject.tp_traverse ` pointer is used by the garbage collector to detect
1070
1098
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.)
1106
1134
.. c :member :: inquiry PyTypeObject.tp_clear
1107
1135
1108
1136
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 *);
1110
1140
1111
1141
The :c:member: `~PyTypeObject.tp_clear ` member function is used to break reference cycles in cyclic
1112
1142
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.)
1164
1194
1165
1195
.. c :member :: richcmpfunc PyTypeObject.tp_richcompare
1166
1196
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 `.
1171
1203
1172
1204
The function should return the result of the comparison (usually ``Py_True ``
1173
1205
or ``Py_False ``). If the comparison is undefined, it must return
@@ -1272,7 +1304,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1272
1304
presence normally signals that the instances of this type are iterable (although
1273
1305
sequences may be iterable without this function).
1274
1306
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);
1276
1310
1277
1311
**Inheritance: **
1278
1312
@@ -1282,6 +1316,10 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1282
1316
.. c :member :: iternextfunc PyTypeObject.tp_iternext
1283
1317
1284
1318
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
+
1285
1323
When the iterator is exhausted, it must return *NULL *; a :exc: `StopIteration `
1286
1324
exception may or may not be set. When another error occurs, it must return
1287
1325
*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.)
1387
1425
1388
1426
An optional pointer to a "descriptor get" function.
1389
1427
1390
- The function signature is ::
1428
+ The function signature is::
1391
1429
1392
1430
PyObject * tp_descr_get(PyObject *self, PyObject *obj, PyObject *type);
1393
1431
1394
- .. XXX explain.
1432
+ .. XXX explain more?
1395
1433
1396
1434
**Inheritance: **
1397
1435
@@ -1403,13 +1441,13 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1403
1441
An optional pointer to a function for setting and deleting
1404
1442
a descriptor's value.
1405
1443
1406
- The function signature is ::
1444
+ The function signature is::
1407
1445
1408
1446
int tp_descr_set(PyObject *self, PyObject *obj, PyObject *value);
1409
1447
1410
1448
The *value * argument is set to *NULL * to delete the value.
1411
1449
1412
- .. XXX explain.
1450
+ .. XXX explain more?
1413
1451
1414
1452
**Inheritance: **
1415
1453
@@ -1485,9 +1523,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1485
1523
:meth: `__init__ `, and it is possible to reinitialize an instance by calling its
1486
1524
:meth: `__init__ ` method again.
1487
1525
1488
- The function signature is ::
1526
+ The function signature is::
1489
1527
1490
- int tp_init(PyObject *self, PyObject *args, PyObject *kwds)
1528
+ int tp_init(PyObject *self, PyObject *args, PyObject *kwds);
1491
1529
1492
1530
The self argument is the instance to be initialized; the *args * and *kwds *
1493
1531
arguments represent positional and keyword arguments of the call to
@@ -1513,9 +1551,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1513
1551
1514
1552
An optional pointer to an instance allocation function.
1515
1553
1516
- The function signature is ::
1554
+ The function signature is::
1517
1555
1518
- PyObject *tp_alloc(PyTypeObject *self, Py_ssize_t nitems)
1556
+ PyObject *tp_alloc(PyTypeObject *self, Py_ssize_t nitems);
1519
1557
1520
1558
**Inheritance: **
1521
1559
@@ -1537,9 +1575,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1537
1575
1538
1576
An optional pointer to an instance creation function.
1539
1577
1540
- The function signature is ::
1578
+ The function signature is::
1541
1579
1542
- PyObject *tp_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds)
1580
+ PyObject *tp_new(PyTypeObject *subtype, PyObject *args, PyObject *kwds);
1543
1581
1544
1582
The subtype argument is the type of the object being created; the *args * and
1545
1583
*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.)
1568
1606
instances, like a factory function.
1569
1607
1570
1608
1571
- .. c :member :: destructor PyTypeObject.tp_free
1609
+ .. c :member :: freefunc PyTypeObject.tp_free
1572
1610
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::
1575
1612
1576
- void tp_free(void *)
1613
+ void tp_free(void *self);
1577
1614
1578
1615
An initializer that is compatible with this signature is :c:func: `PyObject_Free `.
1579
1616
@@ -1601,9 +1638,9 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1601
1638
some types have a mixture of statically and dynamically allocated instances, and
1602
1639
the statically allocated instances are not collectible. Such types should
1603
1640
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::
1605
1642
1606
- int tp_is_gc(PyObject *self)
1643
+ int tp_is_gc(PyObject *self);
1607
1644
1608
1645
(The only example of this are types themselves. The metatype,
1609
1646
:c:data: `PyType_Type `, defines this function to distinguish between statically
@@ -1689,7 +1726,7 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1689
1726
1690
1727
An optional pointer to an instance finalization function. Its signature is::
1691
1728
1692
- void tp_finalize(PyObject *self)
1729
+ void tp_finalize(PyObject *self);
1693
1730
1694
1731
If :c:member: `~PyTypeObject.tp_finalize ` is set, the interpreter calls it once when
1695
1732
finalizing an instance. It is called either from the garbage
@@ -2115,7 +2152,7 @@ Async Object Structures
2115
2152
2116
2153
The signature of this function is::
2117
2154
2118
- PyObject *am_await(PyObject *self)
2155
+ PyObject *am_await(PyObject *self);
2119
2156
2120
2157
The returned object must be an iterator, i.e. :c:func: `PyIter_Check ` must
2121
2158
return ``1 `` for it.
@@ -2126,7 +2163,7 @@ Async Object Structures
2126
2163
2127
2164
The signature of this function is::
2128
2165
2129
- PyObject *am_aiter(PyObject *self)
2166
+ PyObject *am_aiter(PyObject *self);
2130
2167
2131
2168
Must return an :term: `awaitable ` object. See :meth: `__anext__ ` for details.
2132
2169
@@ -2137,7 +2174,7 @@ Async Object Structures
2137
2174
2138
2175
The signature of this function is::
2139
2176
2140
- PyObject *am_anext(PyObject *self)
2177
+ PyObject *am_anext(PyObject *self);
2141
2178
2142
2179
Must return an :term: `awaitable ` object. See :meth: `__anext__ ` for details.
2143
2180
This slot may be set to *NULL *.
@@ -2165,16 +2202,26 @@ Slot Type typedefs
2165
2202
2166
2203
.. c :type :: void (*destructor)(PyObject *)
2167
2204
2168
- .. c :type :: void (*freefunc)(void )
2205
+ .. c :type :: void (*freefunc)(void *)
2206
+
2207
+ See :c:member: `~PyTypeObject.tp_free `.
2169
2208
2170
2209
.. c :type :: PyObject *(*newfunc)(PyObject *, PyObject *, PyObject *)
2171
2210
2211
+ See :c:member: `~PyTypeObject.tp_new `.
2212
+
2172
2213
.. c :type :: int (*initproc)(PyObject *, PyObject *, PyObject *)
2173
2214
2215
+ See :c:member: `~PyTypeObject.tp_init `.
2216
+
2174
2217
.. c :type :: PyObject *(*reprfunc)(PyObject *)
2175
2218
2219
+ See :c:member: `~PyTypeObject.tp_repr `.
2220
+
2176
2221
.. c :type :: int (*printfunc)(PyObject *, FILE *, int )
2177
2222
2223
+ This is hidden if :const: `PY_LIMITED_API ` is set.
2224
+
2178
2225
.. c :type :: PyObject *(*getattrfunc)(PyObject *self, char *attr)
2179
2226
2180
2227
Return the value of the named attribute for the object.
@@ -2188,23 +2235,39 @@ Slot Type typedefs
2188
2235
2189
2236
Return the value of the named attribute for the object.
2190
2237
2238
+ See :c:member: `~PyTypeObject.tp_getattro `.
2239
+
2191
2240
.. c :type :: int (*setattrofunc)(PyObject *self, PyObject *attr, PyObject *value)
2192
2241
2193
2242
Set the value of the named attribute for the object.
2194
2243
The value argument is set to *NULL * to delete the attribute.
2195
2244
2245
+ See :c:member: `~PyTypeObject.tp_setattro `.
2246
+
2196
2247
.. c :type :: PyObject *(*descrgetfunc)(PyObject *, PyObject *, PyObject *)
2197
2248
2249
+ See :c:member: `~PyTypeObject.tp_descrget `.
2250
+
2198
2251
.. c :type :: int (*descrsetfunc)(PyObject *, PyObject *, PyObject *)
2199
2252
2253
+ See :c:member: `~PyTypeObject.tp_descrset `.
2254
+
2200
2255
.. c :type :: Py_hash_t (*hashfunc)(PyObject *)
2201
2256
2257
+ See :c:member: `~PyTypeObject.tp_hash `.
2258
+
2202
2259
.. c :type :: PyObject *(*richcmpfunc)(PyObject *, PyObject *, int )
2203
2260
2261
+ See :c:member: `~PyTypeObject.tp_richcompare `.
2262
+
2204
2263
.. c :type :: PyObject *(*getiterfunc)(PyObject *)
2205
2264
2265
+ See :c:member: `~PyTypeObject.tp_iter `.
2266
+
2206
2267
.. c :type :: PyObject *(*iternextfunc)(PyObject *)
2207
2268
2269
+ See :c:member: `~PyTypeObject.tp_iternext `.
2270
+
2208
2271
.. c :type :: Py_ssize_t (*lenfunc)(PyObject *)
2209
2272
2210
2273
.. c :type :: int (*getbufferproc)(PyObject *, Py_buffer *, int )
0 commit comments