]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-141004: Document `PyType_FastSubclass` (GH-141313)
authorStan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Mon, 10 Nov 2025 17:46:41 +0000 (17:46 +0000)
committerGitHub <noreply@github.com>
Mon, 10 Nov 2025 17:46:41 +0000 (12:46 -0500)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Doc/c-api/type.rst
Doc/c-api/typeobj.rst

index 5bdbff4e0ad990d79d8a3e5a45db2e2c8cffd520..479ede70b01f5d7ee835c11e62a3ee04c28035ec 100644 (file)
@@ -133,6 +133,18 @@ 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 <Py_TPFLAGS_LONG_SUBCLASS>`.
+   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)
 
    Return true if the type object includes support for the cycle detector; this
index 9d23aea5734ea391720aac0752e5e481de286c76..34d19acdf17868b8316bef463d20a57708d5bd3a 100644 (file)
@@ -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:`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`