From bc8102cf4a0ea24b39bda1a9b4ac6d36af38173e Mon Sep 17 00:00:00 2001 From: George Ogden Date: Thu, 19 Feb 2026 11:55:33 +0000 Subject: [PATCH 1/2] Update documentation to describe type(instance) is cls edge case of __instancecheck__ --- Doc/reference/datamodel.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 27aedfa878af9a..a0f12ae5939bce 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -2965,7 +2965,11 @@ ABCs. Return true if *instance* should be considered a (direct or indirect) instance of *class*. If defined, called to implement ``isinstance(instance, - class)``. + cls)``. + + .. note:: + If ``type(instance) is cls`` then ``isinstance(instance, cls)`` is + always ``True`` and ``__instancecheck__`` is not called. .. method:: type.__subclasscheck__(self, subclass) From 038e10c2c55815453bb99dde16a81f9ca6270da4 Mon Sep 17 00:00:00 2001 From: George Ogden Date: Thu, 19 Feb 2026 11:56:38 +0000 Subject: [PATCH 2/2] Update internal documentation to describe type(instance) is cls edge case of PyObject_IsInstance --- Doc/c-api/object.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index f71bfebdb2a19a..6c699ae61f931d 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -433,7 +433,9 @@ Object Protocol If *cls* has a :meth:`~type.__instancecheck__` method, it will be called to determine the subclass status as described in :pep:`3119`. Otherwise, *inst* - is an instance of *cls* if its class is a subclass of *cls*. + is an instance of *cls* if its class is a subclass of *cls*. If *inst* is + an instance of *cls*, this will return ``1`` and will not call + :meth:`~type.__instancecheck__`. An instance *inst* can override what is considered its class by having a :attr:`~object.__class__` attribute.