mirror of
https://github.com/python/cpython.git
synced 2025-07-29 22:24:49 +00:00
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”.
This commit is contained in:
parent
4a1c58d504
commit
1438b77997
1 changed files with 11 additions and 0 deletions
|
@ -1245,6 +1245,17 @@ and :c:type:`PyType_Type` effectively act as defaults.)
|
||||||
**Inheritance:**
|
**Inheritance:**
|
||||||
|
|
||||||
This flag is not inherited.
|
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
|
.. versionadded:: 3.10
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue