Skip to content

[3.10] gh-99249: Clarify "read-only" slots tp_bases & tp_mro (GH-99342) #99838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,16 @@ Quick Reference
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+

.. [#slots]
A slot name in parentheses indicates it is (effectively) deprecated.
Names in angle brackets should be treated as read-only.
Names in square brackets are for internal use only.
"<R>" (as a prefix) means the field is required (must be non-``NULL``).

**()**: A slot name in parentheses indicates it is (effectively) deprecated.

**<>**: Names in angle brackets should be initially set to ``NULL`` and
treated as read-only.

**[]**: Names in square brackets are for internal use only.

**<R>** (as a prefix) means the field is required (must be non-``NULL``).

.. [#cols] Columns:

**"O"**: set on :c:type:`PyBaseObject_Type`
Expand Down Expand Up @@ -1909,8 +1915,19 @@ and :c:type:`PyType_Type` effectively act as defaults.)

Tuple of base types.

This is set for types created by a class statement. It should be ``NULL`` for
statically defined types.
This field should be set to ``NULL`` and treated as read-only.
Python will fill it in when the type is :c:func:`initialized <PyType_Ready>`.

For dynamically created classes, the ``Py_tp_bases``
:c:type:`slot <PyType_Slot>` can be used instead of the *bases* argument
of :c:func:`PyType_FromSpecWithBases`.
The argument form is preferred.

.. warning::

Multiple inheritance does not work well for statically defined types.
If you set ``tp_bases`` to a tuple, Python will not raise an error,
but some slots will only be inherited from the first base.

**Inheritance:**

Expand All @@ -1922,6 +1939,8 @@ and :c:type:`PyType_Type` effectively act as defaults.)
Tuple containing the expanded set of base types, starting with the type itself
and ending with :class:`object`, in Method Resolution Order.

This field should be set to ``NULL`` and treated as read-only.
Python will fill it in when the type is :c:func:`initialized <PyType_Ready>`.

**Inheritance:**

Expand Down