https://github.com/python/cpython/commit/96820d872fb2466bbc8f17baccccd71cd8a05293
commit: 96820d872fb2466bbc8f17baccccd71cd8a05293
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: ZeroIntensity <[email protected]>
date: 2025-11-10T17:52:15Z
summary:

[3.14] gh-141004: Document `PyType_FastSubclass` (GH-141313) (GH-141368)

gh-141004: Document `PyType_FastSubclass` (GH-141313)
(cherry picked from commit ed0a5fd8cacb1964111d03ff37627f6bea5e6026)

Co-authored-by: Stan Ulbrych <[email protected]>
Co-authored-by: Peter Bierma <[email protected]>

files:
M Doc/c-api/type.rst
M Doc/c-api/typeobj.rst

diff --git a/Doc/c-api/type.rst b/Doc/c-api/type.rst
index 5bdbff4e0ad990..479ede70b01f5d 100644
--- a/Doc/c-api/type.rst
+++ b/Doc/c-api/type.rst
@@ -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
diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst
index 3aff9e2d6a972d..a50b61e0468902 100644
--- a/Doc/c-api/typeobj.rst
+++ b/Doc/c-api/typeobj.rst
@@ -1336,8 +1336,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`

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to