Skip to content

Commit 857f6a4

Browse files
[3.11] gh-96746: Docs: Clear up Py_TPFLAGS_DISALLOW_INSTANTIATION inheritance (GH-99002) (GH-99212)
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 3dbf270 commit 857f6a4

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
@@ -1213,6 +1213,17 @@ and :c:type:`PyType_Type` effectively act as defaults.)
12131213
**Inheritance:**
12141214

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

12171228
.. versionadded:: 3.10
12181229

0 commit comments

Comments
 (0)