From 3c2f833f90b82161c6fe240fed98477e98732230 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Sun, 9 Nov 2025 18:30:25 +0000 Subject: [PATCH 1/3] Commit --- Doc/c-api/type.rst | 7 +++++++ Doc/c-api/typeobj.rst | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/type.rst b/Doc/c-api/type.rst index 5bdbff4e0ad990..8117df0234de51 100644 --- a/Doc/c-api/type.rst +++ b/Doc/c-api/type.rst @@ -133,6 +133,13 @@ Type Objects Type features are denoted by single bit flags. +.. c:function:: int PyType_FastSubclass(PyTypeObject *type, int flag) + + Return non-zero if the type object *type* sets the subclass flag *flag*. + Subclass flags are denoted by + :c:macro:`Py_TPFLAGS_*_SUBCLASS `. + + .. c:function:: int PyType_IS_GC(PyTypeObject *o) Return true if the type object includes support for the cycle detector; this diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst index 9d23aea5734ea3..f2a7fa116f2f46 100644 --- a/Doc/c-api/typeobj.rst +++ b/Doc/c-api/typeobj.rst @@ -1351,7 +1351,7 @@ and :c:data:`PyType_Type` effectively act as defaults.) .. c:macro:: Py_TPFLAGS_BASE_EXC_SUBCLASS .. c:macro:: Py_TPFLAGS_TYPE_SUBCLASS - These flags are used by functions such as + These flags are used by functions such as :c:func:`PyType_FastSubclass` and :c:func:`PyLong_Check` to quickly determine if a type is a subclass of a built-in type; such specific checks are faster than a generic check, like :c:func:`PyObject_IsInstance`. Custom types that inherit From 8f0672b6e33949945c5667a435f2ce3a402c791c Mon Sep 17 00:00:00 2001 From: Stan Ulbrych Date: Mon, 10 Nov 2025 07:47:57 +0000 Subject: [PATCH 2/3] review --- Doc/c-api/type.rst | 1 + Doc/c-api/typeobj.rst | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/type.rst b/Doc/c-api/type.rst index 8117df0234de51..daf0e2885291c4 100644 --- a/Doc/c-api/type.rst +++ b/Doc/c-api/type.rst @@ -138,6 +138,7 @@ Type Objects Return non-zero if the type object *type* sets the subclass flag *flag*. Subclass flags are denoted by :c:macro:`Py_TPFLAGS_*_SUBCLASS `. + This function is used by most ``_Check`` functions. .. c:function:: int PyType_IS_GC(PyTypeObject *o) diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst index f2a7fa116f2f46..34d19acdf17868 100644 --- a/Doc/c-api/typeobj.rst +++ b/Doc/c-api/typeobj.rst @@ -1351,8 +1351,8 @@ and :c:data:`PyType_Type` effectively act as defaults.) .. c:macro:: Py_TPFLAGS_BASE_EXC_SUBCLASS .. c:macro:: Py_TPFLAGS_TYPE_SUBCLASS - These flags are used by functions such as :c:func:`PyType_FastSubclass` and - :c:func:`PyLong_Check` to quickly determine if a type is a subclass + Functions such as :c:func:`PyLong_Check` will call :c:func:`PyType_FastSubclass` + with one of these flags to quickly determine if a type is a subclass of a built-in type; such specific checks are faster than a generic check, like :c:func:`PyObject_IsInstance`. Custom types that inherit from built-ins should have their :c:member:`~PyTypeObject.tp_flags` From 5d14d2b5875f69d7e6c2c53ca0c7775d47d61009 Mon Sep 17 00:00:00 2001 From: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Date: Mon, 10 Nov 2025 17:38:40 +0000 Subject: [PATCH 3/3] Apply Peter's suggestion Co-authored-by: Peter Bierma --- Doc/c-api/type.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/type.rst b/Doc/c-api/type.rst index daf0e2885291c4..479ede70b01f5d 100644 --- a/Doc/c-api/type.rst +++ b/Doc/c-api/type.rst @@ -138,7 +138,11 @@ Type Objects Return non-zero if the type object *type* sets the subclass flag *flag*. Subclass flags are denoted by :c:macro:`Py_TPFLAGS_*_SUBCLASS `. - This function is used by most ``_Check`` functions. + This function is used by many ``_Check`` functions for common types. + + .. seealso:: + :c:func:`PyObject_TypeCheck`, which is used as a slower alternative in + ``_Check`` functions for types that don't come with subclass flags. .. c:function:: int PyType_IS_GC(PyTypeObject *o)