[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 1438b77997)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
This commit is contained in:
Miss Islington (bot) 2022-11-07 10:55:58 -08:00 committed by GitHub
parent 3dbf2708f5
commit 857f6a44a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1213,6 +1213,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