]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-96746: Docs: Clear up Py_TPFLAGS_DISALLOW_INSTANTIATION inheritance (GH-99002)
authorPetr Viktorin <encukou@gmail.com>
Mon, 7 Nov 2022 18:45:50 +0000 (19:45 +0100)
committerGitHub <noreply@github.com>
Mon, 7 Nov 2022 18:45:50 +0000 (19:45 +0100)
The flag is not inherited, but its effect -- a NULL tp_new -- is.

Drop hints for people who come here wanting to “disallow instantiation”.

Doc/c-api/typeobj.rst

index 8ccdece3efc54c9cc05c4bccf3a5b12428edb483..4c462f460567392498a5e78fe67a9ffec2de4a37 100644 (file)
@@ -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