summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetr Viktorin <encukou@gmail.com>2022-11-07 18:45:50 (GMT)
committerGitHub <noreply@github.com>2022-11-07 18:45:50 (GMT)
commit1438b779971605e516bd0a4051a704d6ffbbd58d (patch)
tree578698b69d07e4f6877af41a9557f9c0cc12251b
parent4a1c58d504a49eeb9be7beef3ca861a9d6b28ede (diff)
downloadcpython-1438b779971605e516bd0a4051a704d6ffbbd58d.zip
cpython-1438b779971605e516bd0a4051a704d6ffbbd58d.tar.gz
cpython-1438b779971605e516bd0a4051a704d6ffbbd58d.tar.bz2
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”.
-rw-r--r--Doc/c-api/typeobj.rst11
1 files changed, 11 insertions, 0 deletions
diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst
index 8ccdece..4c462f4 100644
--- a/Doc/c-api/typeobj.rst
+++ b/Doc/c-api/typeobj.rst
@@ -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