Skip to content

Commit d2cb0f9

Browse files
[3.10] gh-96746: Docs: Clear up Py_TPFLAGS_DISALLOW_INSTANTIATION inheritance (GH-99002) (GH-99213)
gh-96746: Docs: Clear up Py_TPFLAGS_DISALLOW_INSTANTIATION inheritance (GH-99002) The flag is not inherited, but its effect -- a NULL tp_new -- is. Drop hints for people who come here wanting to “disallow instantiation”. (cherry picked from commit 1438b77) Co-authored-by: Petr Viktorin <[email protected]>
1 parent 6b46cb4 commit d2cb0f9

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Doc/c-api/typeobj.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1212,6 +1212,17 @@ and :c:type:`PyType_Type` effectively act as defaults.)
12121212
**Inheritance:**
12131213

12141214
This flag is not inherited.
1215+
However, subclasses will not be instantiable unless they provide a
1216+
non-NULL :c:member:`~PyTypeObject.tp_new` (which is only possible
1217+
via the C API).
1218+
1219+
.. note::
1220+
1221+
To disallow instantiating a class directly but allow instantiating
1222+
its subclasses (e.g. for an :term:`abstract base class`),
1223+
do not use this flag.
1224+
Instead, make :c:member:`~PyTypeObject.tp_new` only succeed for
1225+
subclasses.
12151226

12161227
.. versionadded:: 3.10
12171228

0 commit comments

Comments
 (0)