mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
[3.12] gh-110803: Reorganize docs for what PyType_Slot doesn't cover (GH-110813) (#110823)
gh-110803: Reorganize docs for what PyType_Slot doesn't cover (GH-110813)
* gh-110803: Reorganize docs for what PyType_Slot doesn't cover
- Cover the offset fields first
- Mention the old alternative for MANAGED flags, which is needed
to support older Pythons
- De-emphasize the internal flags: use an inline list.
- Add a note to PyMemberDef saying what to do with it
* Remove an older draft...
(cherry picked from commit 2ab34f0e42
)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
parent
08242cdd7b
commit
f2e353b9d8
2 changed files with 31 additions and 14 deletions
|
@ -406,7 +406,11 @@ Accessing attributes of extension types
|
||||||
.. c:type:: PyMemberDef
|
.. c:type:: PyMemberDef
|
||||||
|
|
||||||
Structure which describes an attribute of a type which corresponds to a C
|
Structure which describes an attribute of a type which corresponds to a C
|
||||||
struct member. Its fields are, in order:
|
struct member.
|
||||||
|
When defining a class, put a NULL-terminated array of these
|
||||||
|
structures in the :c:member:`~PyTypeObject.tp_members` slot.
|
||||||
|
|
||||||
|
Its fields are, in order:
|
||||||
|
|
||||||
.. c:member:: const char* name
|
.. c:member:: const char* name
|
||||||
|
|
||||||
|
|
|
@ -461,21 +461,34 @@ The following functions and structs are used to create
|
||||||
* ``Py_nb_add`` to set :c:member:`PyNumberMethods.nb_add`
|
* ``Py_nb_add`` to set :c:member:`PyNumberMethods.nb_add`
|
||||||
* ``Py_sq_length`` to set :c:member:`PySequenceMethods.sq_length`
|
* ``Py_sq_length`` to set :c:member:`PySequenceMethods.sq_length`
|
||||||
|
|
||||||
The following fields cannot be set at all using :c:type:`PyType_Spec` and
|
The following “offset” fields cannot be set using :c:type:`PyType_Slot`:
|
||||||
:c:type:`PyType_Slot`:
|
|
||||||
|
* :c:member:`~PyTypeObject.tp_weaklistoffset`
|
||||||
|
(use :c:macro:`Py_TPFLAGS_MANAGED_WEAKREF` instead if possible)
|
||||||
|
* :c:member:`~PyTypeObject.tp_dictoffset`
|
||||||
|
(use :c:macro:`Py_TPFLAGS_MANAGED_DICT` instead if possible)
|
||||||
|
* :c:member:`~PyTypeObject.tp_vectorcall_offset`
|
||||||
|
(use ``"__vectorcalloffset__"`` in
|
||||||
|
:ref:`PyMemberDef <pymemberdef-offsets>`)
|
||||||
|
|
||||||
|
If it is not possible to switch to a ``MANAGED`` flag (for example,
|
||||||
|
for vectorcall or to support Python older than 3.12), specify the
|
||||||
|
offset in :c:member:`Py_tp_members <PyTypeObject.tp_members>`.
|
||||||
|
See :ref:`PyMemberDef documentation <pymemberdef-offsets>`
|
||||||
|
for details.
|
||||||
|
|
||||||
|
The following fields cannot be set at all when creating a heap type:
|
||||||
|
|
||||||
* :c:member:`~PyTypeObject.tp_dict`
|
|
||||||
* :c:member:`~PyTypeObject.tp_mro`
|
|
||||||
* :c:member:`~PyTypeObject.tp_cache`
|
|
||||||
* :c:member:`~PyTypeObject.tp_subclasses`
|
|
||||||
* :c:member:`~PyTypeObject.tp_weaklist`
|
|
||||||
* :c:member:`~PyTypeObject.tp_vectorcall`
|
* :c:member:`~PyTypeObject.tp_vectorcall`
|
||||||
* :c:member:`~PyTypeObject.tp_weaklistoffset`
|
(use :c:member:`~PyTypeObject.tp_new` and/or
|
||||||
(use :c:macro:`Py_TPFLAGS_MANAGED_WEAKREF` instead)
|
:c:member:`~PyTypeObject.tp_init`)
|
||||||
* :c:member:`~PyTypeObject.tp_dictoffset`
|
|
||||||
(use :c:macro:`Py_TPFLAGS_MANAGED_DICT` instead)
|
* Internal fields:
|
||||||
* :c:member:`~PyTypeObject.tp_vectorcall_offset`
|
:c:member:`~PyTypeObject.tp_dict`,
|
||||||
(see :ref:`PyMemberDef <pymemberdef-offsets>`)
|
:c:member:`~PyTypeObject.tp_mro`,
|
||||||
|
:c:member:`~PyTypeObject.tp_cache`,
|
||||||
|
:c:member:`~PyTypeObject.tp_subclasses`, and
|
||||||
|
:c:member:`~PyTypeObject.tp_weaklist`.
|
||||||
|
|
||||||
Setting :c:data:`Py_tp_bases` or :c:data:`Py_tp_base` may be
|
Setting :c:data:`Py_tp_bases` or :c:data:`Py_tp_base` may be
|
||||||
problematic on some platforms.
|
problematic on some platforms.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue