Skip to content

gh-96746: Docs: Clear up Py_TPFLAGS_DISALLOW_INSTANTIATION inheritance #99002

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 7, 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
11 changes: 11 additions & 0 deletions Doc/c-api/typeobj.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1245,6 +1245,17 @@ and :c:type:`PyType_Type` effectively act as defaults.)
**Inheritance:**

This flag is not inherited.
However, subclasses will not be instantiable unless they provide a
non-NULL :c:member:`~PyTypeObject.tp_new` (which is only possible
via the C API).

.. note::

To disallow instantiating a class directly but allow instantiating
its subclasses (e.g. for an :term:`abstract base class`),
do not use this flag.
Instead, make :c:member:`~PyTypeObject.tp_new` only succeed for
subclasses.

.. versionadded:: 3.10

Expand Down