From 56f020fa7d3a9cda5cc768d279d246cad85313de Mon Sep 17 00:00:00 2001 From: fatelei Date: Mon, 20 Oct 2025 10:09:54 +0800 Subject: [PATCH] =?UTF-8?q?gh-140160:=20Rework=20PyObject=5FIsSubclass=20d?= =?UTF-8?q?ocumentation=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Doc/c-api/object.rst | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index 8629b768a2948e..a0e4f599ca0d06 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -376,21 +376,17 @@ Object Protocol .. c:function:: int PyObject_IsSubclass(PyObject *derived, PyObject *cls) - Return ``1`` if the class *derived* is identical to or derived from the class - *cls*, otherwise return ``0``. In case of an error, return ``-1``. + Return ``1`` if *derived* is a subclass of *cls*, ``0`` if not, or ``-1`` on + error. - If *cls* is a tuple, the check will be done against every entry in *cls*. - The result will be ``1`` when at least one of the checks returns ``1``, - otherwise it will be ``0``. - - If *cls* has a :meth:`~type.__subclasscheck__` method, it will be called to - determine the subclass status as described in :pep:`3119`. Otherwise, - *derived* is a subclass of *cls* if it is a direct or indirect subclass, - i.e. contained in :attr:`cls.__mro__ `. + If *cls* is a tuple, return ``1`` if *derived* is a subclass of any entry in + *cls*. - Normally only class objects, i.e. instances of :class:`type` or a derived - class, are considered classes. However, objects can override this by having - a :attr:`~type.__bases__` attribute (which must be a tuple of base classes). + The check respects :meth:`~type.__subclasscheck__` method if defined (see + :pep:`3119`); otherwise, checks whether *derived* is in + :attr:`cls.__mro__ `. Non-class objects with a + :attr:`~type.__bases__` attribute (which must be a tuple of base classes) + are also supported. .. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls)