Skip to content

Commit 1438b77

Browse files
authored
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”.
1 parent 4a1c58d commit 1438b77

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

12471247
This flag is not inherited.
1248+
However, subclasses will not be instantiable unless they provide a
1249+
non-NULL :c:member:`~PyTypeObject.tp_new` (which is only possible
1250+
via the C API).
1251+
1252+
.. note::
1253+
1254+
To disallow instantiating a class directly but allow instantiating
1255+
its subclasses (e.g. for an :term:`abstract base class`),
1256+
do not use this flag.
1257+
Instead, make :c:member:`~PyTypeObject.tp_new` only succeed for
1258+
subclasses.
12481259

12491260
.. versionadded:: 3.10
12501261

0 commit comments

Comments
 (0)