diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2022-11-07 18:56:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-07 18:56:21 (GMT) |
commit | d2cb0f91178ed97e3a7509f7d5fca50a39880c3d (patch) | |
tree | e039dffa24327b0cc6bffeaf61fd7efc25604416 /Doc/c-api | |
parent | 6b46cb4d3380282476a2233b17b2164a75396846 (diff) | |
download | cpython-d2cb0f91178ed97e3a7509f7d5fca50a39880c3d.zip cpython-d2cb0f91178ed97e3a7509f7d5fca50a39880c3d.tar.gz cpython-d2cb0f91178ed97e3a7509f7d5fca50a39880c3d.tar.bz2 |
[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 1438b779971605e516bd0a4051a704d6ffbbd58d)
Co-authored-by: Petr Viktorin <encukou@gmail.com>
Diffstat (limited to 'Doc/c-api')
-rw-r--r-- | Doc/c-api/typeobj.rst | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst index 21385af..b8ec2e1 100644 --- a/Doc/c-api/typeobj.rst +++ b/Doc/c-api/typeobj.rst @@ -1212,6 +1212,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 |