@@ -135,7 +135,7 @@ Quick Reference
135
135
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
136
136
| [:c:member: `~PyTypeObject.tp_cache `] | :c:type: `PyObject ` * | | | | |
137
137
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
138
- | [:c:member: `~PyTypeObject.tp_subclasses `] | :c:type: ` PyObject ` * | __subclasses__ | | | |
138
+ | [:c:member: `~PyTypeObject.tp_subclasses `] | void * | __subclasses__ | | | |
139
139
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
140
140
| [:c:member: `~PyTypeObject.tp_weaklist `] | :c:type: `PyObject ` * | | | | |
141
141
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
@@ -720,29 +720,29 @@ and :c:type:`PyType_Type` effectively act as defaults.)
720
720
with the *vectorcallfunc * function.
721
721
This can be done by setting *tp_call * to :c:func: `PyVectorcall_Call `.
722
722
723
- .. warning ::
724
-
725
- It is not recommended for :ref: `mutable heap types <heap-types >` to implement
726
- the vectorcall protocol.
727
- When a user sets :attr: `__call__ ` in Python code, only *tp_call * is updated,
728
- likely making it inconsistent with the vectorcall function.
729
-
730
723
.. versionchanged :: 3.8
731
724
732
725
Before version 3.8, this slot was named ``tp_print ``.
733
726
In Python 2.x, it was used for printing to a file.
734
727
In Python 3.0 to 3.7, it was unused.
735
728
729
+ .. versionchanged :: 3.12
730
+
731
+ Before version 3.12, it was not recommended for
732
+ :ref: `mutable heap types <heap-types >` to implement the vectorcall
733
+ protocol.
734
+ When a user sets :attr: `~type.__call__ ` in Python code, only *tp_call * is
735
+ updated, likely making it inconsistent with the vectorcall function.
736
+ Since 3.12, setting ``__call__ `` will disable vectorcall optimization
737
+ by clearing the :const: `Py_TPFLAGS_HAVE_VECTORCALL ` flag.
738
+
736
739
**Inheritance: **
737
740
738
741
This field is always inherited.
739
742
However, the :const: `Py_TPFLAGS_HAVE_VECTORCALL ` flag is not
740
- always inherited. If it's not, then the subclass won't use
743
+ always inherited. If it's not set , then the subclass won't use
741
744
:ref: `vectorcall <vectorcall >`, except when
742
745
:c:func: `PyVectorcall_Call ` is explicitly called.
743
- This is in particular the case for types without the
744
- :const: `Py_TPFLAGS_IMMUTABLETYPE ` flag set (including subclasses defined in
745
- Python).
746
746
747
747
748
748
.. c :member :: getattrfunc PyTypeObject.tp_getattr
@@ -1178,12 +1178,18 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1178
1178
1179
1179
**Inheritance: **
1180
1180
1181
- This bit is inherited for types with the
1182
- :const: `Py_TPFLAGS_IMMUTABLETYPE ` flag set, if
1183
- :c:member: `~PyTypeObject.tp_call ` is also inherited.
1181
+ This bit is inherited if :c:member: `~PyTypeObject.tp_call ` is also
1182
+ inherited.
1184
1183
1185
1184
.. versionadded :: 3.9
1186
1185
1186
+ .. versionchanged :: 3.12
1187
+
1188
+ This flag is now removed from a class when the class's
1189
+ :py:meth: `~object.__call__ ` method is reassigned.
1190
+
1191
+ This flag can now be inherited by mutable classes.
1192
+
1187
1193
.. data :: Py_TPFLAGS_IMMUTABLETYPE
1188
1194
1189
1195
This bit is set for type objects that are immutable: type attributes cannot be set nor deleted.
@@ -1709,18 +1715,11 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1709
1715
:c:member: `~PyTypeObject.tp_dictoffset ` should be set to ``-4 `` to indicate that the dictionary is
1710
1716
at the very end of the structure.
1711
1717
1712
- The real dictionary offset in an instance can be computed from a negative
1713
- :c:member: `~PyTypeObject.tp_dictoffset ` as follows::
1714
-
1715
- dictoffset = tp_basicsize + abs(ob_size)*tp_itemsize + tp_dictoffset
1716
- if dictoffset is not aligned on sizeof(void*):
1717
- round up to sizeof(void*)
1718
-
1719
- where :c:member: `~PyTypeObject.tp_basicsize `, :c:member: `~PyTypeObject.tp_itemsize ` and :c:member: `~PyTypeObject.tp_dictoffset ` are
1720
- taken from the type object, and :attr: `ob_size ` is taken from the instance. The
1721
- absolute value is taken because ints use the sign of :attr: `ob_size ` to
1722
- store the sign of the number. (There's never a need to do this calculation
1723
- yourself; it is done for you by :c:func: `_PyObject_GetDictPtr `.)
1718
+ The :c:member: `~PyTypeObject.tp_dictoffset ` should be regarded as write-only.
1719
+ To get the pointer to the dictionary call :c:func: `PyObject_GenericGetDict `.
1720
+ Calling :c:func: `PyObject_GenericGetDict ` may need to allocate memory for the
1721
+ dictionary, so it is may be more efficient to call :c:func: `PyObject_GetAttr `
1722
+ when accessing an attribute on the object.
1724
1723
1725
1724
**Inheritance: **
1726
1725
@@ -1928,9 +1927,17 @@ and :c:type:`PyType_Type` effectively act as defaults.)
1928
1927
This field is not inherited.
1929
1928
1930
1929
1931
- .. c :member :: PyObject* PyTypeObject.tp_subclasses
1930
+ .. c :member :: void * PyTypeObject.tp_subclasses
1931
+
1932
+ A collection of subclasses. Internal use only. May be an invalid pointer.
1933
+
1934
+ To get a list of subclasses, call the Python method
1935
+ :py:meth: `~class.__subclasses__ `.
1936
+
1937
+ .. versionchanged :: 3.12
1932
1938
1933
- List of weak references to subclasses. Internal use only.
1939
+ For some types, this field does not hold a valid :c:expr: `PyObject* `.
1940
+ The type was changed to :c:expr: `void* ` to indicate this.
1934
1941
1935
1942
**Inheritance: **
1936
1943
0 commit comments