Skip to content

Commit d158413

Browse files
miss-islingtonStanFromIrelandZeroIntensity
authored
[3.13] gh-141004: Document PyType_FastSubclass (GH-141313) (GH-141369)
gh-141004: Document `PyType_FastSubclass` (GH-141313) (cherry picked from commit ed0a5fd) Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent 1f9f8e5 commit d158413

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Doc/c-api/type.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ Type Objects
133133
Type features are denoted by single bit flags.
134134
135135
136+
.. c:function:: int PyType_FastSubclass(PyTypeObject *type, int flag)
137+
138+
Return non-zero if the type object *type* sets the subclass flag *flag*.
139+
Subclass flags are denoted by
140+
:c:macro:`Py_TPFLAGS_*_SUBCLASS <Py_TPFLAGS_LONG_SUBCLASS>`.
141+
This function is used by many ``_Check`` functions for common types.
142+
143+
.. seealso::
144+
:c:func:`PyObject_TypeCheck`, which is used as a slower alternative in
145+
``_Check`` functions for types that don't come with subclass flags.
146+
147+
136148
.. c:function:: int PyType_IS_GC(PyTypeObject *o)
137149
138150
Return true if the type object includes support for the cycle detector; this

Doc/c-api/typeobj.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,8 +1248,8 @@ and :c:data:`PyType_Type` effectively act as defaults.)
12481248
.. c:macro:: Py_TPFLAGS_BASE_EXC_SUBCLASS
12491249
.. c:macro:: Py_TPFLAGS_TYPE_SUBCLASS
12501250
1251-
These flags are used by functions such as
1252-
:c:func:`PyLong_Check` to quickly determine if a type is a subclass
1251+
Functions such as :c:func:`PyLong_Check` will call :c:func:`PyType_FastSubclass`
1252+
with one of these flags to quickly determine if a type is a subclass
12531253
of a built-in type; such specific checks are faster than a generic
12541254
check, like :c:func:`PyObject_IsInstance`. Custom types that inherit
12551255
from built-ins should have their :c:member:`~PyTypeObject.tp_flags`

0 commit comments

Comments
 (0)