From df3297b29acbf84954e90e1757aaa82093b63f96 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Thu, 9 Mar 2023 14:10:24 +0300 Subject: [PATCH 01/18] Explain __base__ attribute in the docs --- Doc/c-api/object.rst | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index 84c72e7e108b64..f6c601931590fd 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -245,6 +245,46 @@ Object Protocol class, are considered classes. However, objects can override this by having a :attr:`__bases__` attribute (which must be a tuple of base classes). + Another function, :attr:`__base__` that is specific to Cpython and also + exists in Jython and PyPy can also be used on a class inheriting from one + or more classes. When such a class takes arguments in the correct order, + then starting leftmost. + + Let's look at the example cases; + + >>> class A(object): pass + ... + >>> class B(A): pass + ... + >>> class C(int): pass + ... + + The first user-defined class that either inherits from the instance + of a built-in type other than object or inherits from another user + defined class (single or multiple inheritance) that does so or in the + absence of the above class. + + >>> class D(B, A, C): pass + ... + >>> D.__base__ + + >>> + + A built-in type that is not an object or in the absence of the above class. + + >>> class D(B, A, int): pass + ... + >>> D.__base__ + + + The first user defined class that inherits either an object or + derives from a class (directly or indirectly) that inherits an + object is the value returned by the :attr:`__base__` function. + + >>> class D(B, A): pass + ... + >>> D.__base__ + .. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls) From 7997fc942ed8ebf71b82658c82ce493f05cddbf9 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Thu, 9 Mar 2023 14:39:36 +0300 Subject: [PATCH 02/18] explain __base__ attribute in the stdtypes doc --- Doc/library/stdtypes.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 98bda6ded30f79..9862c107f5e2aa 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5445,6 +5445,15 @@ types, where they are relevant. Some of these are not reported by the The tuple of base classes of a class object. +.. attribute:: class.__base__ + + ``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base` in a + type object. At the C level, Python has a single inheritance model + that determines the memory layout of instances. There is a chain + involving base classes that contribute to the instance layout. + ``__base__`` is the base class that is involved in that chain. + + .. attribute:: definition.__name__ The name of the class, function, method, descriptor, or From 933f8f3078f1cfd33a7be282be7e22f2e142c75a Mon Sep 17 00:00:00 2001 From: furkanonder Date: Thu, 9 Mar 2023 14:39:48 +0300 Subject: [PATCH 03/18] explain __base__ attribute in the datamodel doc --- Doc/reference/datamodel.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index e4e471e50079ae..d31e05e63d8388 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -853,6 +853,13 @@ Custom classes A tuple containing the base classes, in the order of their occurrence in the base class list. + :attr:`~class.__base__` + ``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base` in a + type object. At the C level, Python has a single inheritance model + that determines the memory layout of instances. There is a chain + involving base classes that contribute to the instance layout. + ``__base__`` is the base class that is involved in that chain. + :attr:`__doc__` The class's documentation string, or ``None`` if undefined. From 53be24008e1b032d40f5d44be0f1b52dc3587504 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Thu, 9 Mar 2023 15:12:27 +0300 Subject: [PATCH 04/18] Add note to the __base__ attribute explanation --- Doc/c-api/object.rst | 2 ++ Doc/library/stdtypes.rst | 2 ++ Doc/reference/datamodel.rst | 3 +++ 3 files changed, 7 insertions(+) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index f6c601931590fd..b3355dd89c6e99 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -286,6 +286,8 @@ Object Protocol >>> D.__base__ + Note that behavior of the ``__base__`` attribute is dependent on the CPython implementation. + .. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls) Return ``1`` if *inst* is an instance of the class *cls* or a subclass of diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index 9862c107f5e2aa..ab8362c1acbc5b 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5453,6 +5453,8 @@ types, where they are relevant. Some of these are not reported by the involving base classes that contribute to the instance layout. ``__base__`` is the base class that is involved in that chain. + .. note:: + The behavior of the ``__base__`` attribute is dependent on the CPython implementation. .. attribute:: definition.__name__ diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index d31e05e63d8388..2d43a20d2c8b93 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -860,6 +860,9 @@ Custom classes involving base classes that contribute to the instance layout. ``__base__`` is the base class that is involved in that chain. + .. note:: + The behavior of the ``__base__`` attribute is dependent on the CPython implementation. + :attr:`__doc__` The class's documentation string, or ``None`` if undefined. From 548abb8c25f1a4152f65f68b5d4d63bad3faa4e5 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Thu, 9 Mar 2023 15:22:32 +0300 Subject: [PATCH 05/18] fix doc tests --- Doc/c-api/object.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index b3355dd89c6e99..7166f3b441eda6 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -267,7 +267,7 @@ Object Protocol >>> class D(B, A, C): pass ... >>> D.__base__ - + >>> A built-in type that is not an object or in the absence of the above class. @@ -275,7 +275,7 @@ Object Protocol >>> class D(B, A, int): pass ... >>> D.__base__ - + The first user defined class that inherits either an object or derives from a class (directly or indirectly) that inherits an @@ -284,7 +284,7 @@ Object Protocol >>> class D(B, A): pass ... >>> D.__base__ - + Note that behavior of the ``__base__`` attribute is dependent on the CPython implementation. From 90c3b744412a16fe40e45a133186bca0f949e31b Mon Sep 17 00:00:00 2001 From: furkanonder Date: Tue, 14 Mar 2023 00:20:26 +0300 Subject: [PATCH 06/18] Use right markup for CPython implementation --- Doc/c-api/object.rst | 2 +- Doc/library/stdtypes.rst | 2 +- Doc/reference/datamodel.rst | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index 7166f3b441eda6..4ee214484fabb8 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -286,7 +286,7 @@ Object Protocol >>> D.__base__ - Note that behavior of the ``__base__`` attribute is dependent on the CPython implementation. + Note that behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. .. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index ab8362c1acbc5b..ff6cd0a1813c48 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5454,7 +5454,7 @@ types, where they are relevant. Some of these are not reported by the ``__base__`` is the base class that is involved in that chain. .. note:: - The behavior of the ``__base__`` attribute is dependent on the CPython implementation. + The behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. .. attribute:: definition.__name__ diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 2d43a20d2c8b93..ac40b1e9d1c741 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -861,7 +861,7 @@ Custom classes ``__base__`` is the base class that is involved in that chain. .. note:: - The behavior of the ``__base__`` attribute is dependent on the CPython implementation. + The behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. :attr:`__doc__` The class's documentation string, or ``None`` if undefined. From 6d1ad66d18bb2543d7b98b4d3d68a8761ee074fa Mon Sep 17 00:00:00 2001 From: furkanonder Date: Tue, 14 Mar 2023 00:32:48 +0300 Subject: [PATCH 07/18] Use impl-detail:: markup instead of note:: --- Doc/c-api/object.rst | 3 ++- Doc/library/stdtypes.rst | 2 +- Doc/reference/datamodel.rst | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index 4ee214484fabb8..09d231c6aa2917 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -286,7 +286,8 @@ Object Protocol >>> D.__base__ - Note that behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. + .. impl-detail:: + Note that behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. .. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index ff6cd0a1813c48..dbe685a7f4bf95 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5453,7 +5453,7 @@ types, where they are relevant. Some of these are not reported by the involving base classes that contribute to the instance layout. ``__base__`` is the base class that is involved in that chain. - .. note:: + .. impl-detail:: The behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. .. attribute:: definition.__name__ diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index ac40b1e9d1c741..3d9ca587f20840 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -860,7 +860,7 @@ Custom classes involving base classes that contribute to the instance layout. ``__base__`` is the base class that is involved in that chain. - .. note:: + .. impl-detail:: The behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. :attr:`__doc__` From b6769583df8affebfe6315cf1e5a1818e3a38a54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric?= Date: Thu, 11 May 2023 10:07:43 -0400 Subject: [PATCH 08/18] harmonize indentation --- Doc/reference/datamodel.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 3d9ca587f20840..d2b2c618e6142d 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -854,13 +854,13 @@ Custom classes their occurrence in the base class list. :attr:`~class.__base__` - ``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base` in a - type object. At the C level, Python has a single inheritance model - that determines the memory layout of instances. There is a chain - involving base classes that contribute to the instance layout. - ``__base__`` is the base class that is involved in that chain. + ``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base` in a + type object. At the C level, Python has a single inheritance model + that determines the memory layout of instances. There is a chain + involving base classes that contribute to the instance layout. + ``__base__`` is the base class that is involved in that chain. - .. impl-detail:: + .. impl-detail:: The behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. :attr:`__doc__` From 68e557b5078fe0136df7ebab1a563718d36bc839 Mon Sep 17 00:00:00 2001 From: Furkan Onder Date: Sun, 21 Jan 2024 02:12:59 +0300 Subject: [PATCH 09/18] fix wording for CPython --- Doc/c-api/object.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index 09d231c6aa2917..7a19cf62839b1b 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -245,7 +245,7 @@ Object Protocol class, are considered classes. However, objects can override this by having a :attr:`__bases__` attribute (which must be a tuple of base classes). - Another function, :attr:`__base__` that is specific to Cpython and also + Another function, :attr:`__base__` that is specific to CPython and also exists in Jython and PyPy can also be used on a class inheriting from one or more classes. When such a class takes arguments in the correct order, then starting leftmost. From 01c2912df532f397a0621964b9a820b8f6ca8547 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Mon, 22 Jan 2024 00:36:58 +0300 Subject: [PATCH 10/18] remove __base__ explaination in the object.rst and stdtypes.rst --- Doc/c-api/object.rst | 43 ---------------------------------------- Doc/library/stdtypes.rst | 11 ---------- 2 files changed, 54 deletions(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index 06c9d62a7e4cef..8a179690d048e3 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -307,49 +307,6 @@ Object Protocol class, are considered classes. However, objects can override this by having a :attr:`~class.__bases__` attribute (which must be a tuple of base classes). - Another function, :attr:`__base__` that is specific to CPython and also - exists in Jython and PyPy can also be used on a class inheriting from one - or more classes. When such a class takes arguments in the correct order, - then starting leftmost. - - Let's look at the example cases; - - >>> class A(object): pass - ... - >>> class B(A): pass - ... - >>> class C(int): pass - ... - - The first user-defined class that either inherits from the instance - of a built-in type other than object or inherits from another user - defined class (single or multiple inheritance) that does so or in the - absence of the above class. - - >>> class D(B, A, C): pass - ... - >>> D.__base__ - - >>> - - A built-in type that is not an object or in the absence of the above class. - - >>> class D(B, A, int): pass - ... - >>> D.__base__ - - - The first user defined class that inherits either an object or - derives from a class (directly or indirectly) that inherits an - object is the value returned by the :attr:`__base__` function. - - >>> class D(B, A): pass - ... - >>> D.__base__ - - - .. impl-detail:: - Note that behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. .. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index ee15f4ea7a10b3..9028ff5c134fa9 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5492,17 +5492,6 @@ types, where they are relevant. Some of these are not reported by the The tuple of base classes of a class object. -.. attribute:: class.__base__ - - ``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base` in a - type object. At the C level, Python has a single inheritance model - that determines the memory layout of instances. There is a chain - involving base classes that contribute to the instance layout. - ``__base__`` is the base class that is involved in that chain. - - .. impl-detail:: - The behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. - .. attribute:: definition.__name__ The name of the class, function, method, descriptor, or From 53bd224ee64d3aaf8d14482ac5d64dffac106cc3 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Mon, 22 Jan 2024 00:56:26 +0300 Subject: [PATCH 11/18] remove __base__ explaination in the datamodel.rst --- Doc/reference/datamodel.rst | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index a1535acd394994..ca29a3712dfa38 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -982,16 +982,6 @@ Special attributes: :attr:`~object.__dict__` The dictionary containing the class's namespace. - :attr:`~class.__base__` - ``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base` in a - type object. At the C level, Python has a single inheritance model - that determines the memory layout of instances. There is a chain - involving base classes that contribute to the instance layout. - ``__base__`` is the base class that is involved in that chain. - - .. impl-detail:: - The behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. - :attr:`~class.__bases__` A tuple containing the base classes, in the order of their occurrence in the base class list. From dabe938649a0dcaa2d612f03249408ee106651b0 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Mon, 22 Jan 2024 00:56:31 +0300 Subject: [PATCH 12/18] add __base__ explaination into Doc/c-api/object.rst --- Doc/c-api/object.rst | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index 8a179690d048e3..6f22c6a724ca6f 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -307,6 +307,56 @@ Object Protocol class, are considered classes. However, objects can override this by having a :attr:`~class.__bases__` attribute (which must be a tuple of base classes). + Another function, :attr:`__base__` that is specific to CPython and also + exists in Jython and PyPy can also be used on a class inheriting from one + or more classes. + + ``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base` in a + type object. At the C level, Python has a single inheritance model + that determines the memory layout of instances. There is a chain + involving base classes that contribute to the instance layout. + ``__base__`` is the base class that is involved in that chain. + When such a class takes arguments in the correct order, then starting leftmost. + + Let's look at the example cases; + + >>> class A(object): pass + ... + >>> class B(A): pass + ... + >>> class C(int): pass + ... + + The first user-defined class that either inherits from the instance + of a built-in type other than object or inherits from another user + defined class (single or multiple inheritance) that does so or in the + absence of the above class. + + >>> class D(B, A, C): pass + ... + >>> D.__base__ + + >>> + + A built-in type that is not an object or in the absence of the above class. + + >>> class D(B, A, int): pass + ... + >>> D.__base__ + + + The first user defined class that inherits either an object or + derives from a class (directly or indirectly) that inherits an + object is the value returned by the :attr:`__base__` function. + + >>> class D(B, A): pass + ... + >>> D.__base__ + + + .. impl-detail:: + Note that behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. + .. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls) From f0fb022b3c16cb30ae4c7588c63b070829161ab6 Mon Sep 17 00:00:00 2001 From: Furkan Onder Date: Mon, 22 Jan 2024 03:55:21 +0300 Subject: [PATCH 13/18] Use :attr:`~class.__base__` instead of :attr:`__base__` --- Doc/c-api/object.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index 6f22c6a724ca6f..d510a862fc4255 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -307,7 +307,7 @@ Object Protocol class, are considered classes. However, objects can override this by having a :attr:`~class.__bases__` attribute (which must be a tuple of base classes). - Another function, :attr:`__base__` that is specific to CPython and also + Another function, :attr:`~class.__base__` that is specific to CPython and also exists in Jython and PyPy can also be used on a class inheriting from one or more classes. @@ -347,7 +347,7 @@ Object Protocol The first user defined class that inherits either an object or derives from a class (directly or indirectly) that inherits an - object is the value returned by the :attr:`__base__` function. + object is the value returned by the :attr:`~class.__base__` function. >>> class D(B, A): pass ... From 15b86497ada129fb0d9695c02c14988d0fd18bd0 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Wed, 20 Aug 2025 14:33:47 +0300 Subject: [PATCH 14/18] Fix __base__ attribute references and description --- Doc/c-api/object.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index da1b5797f2c33b..64f1c7bc27cef5 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -392,9 +392,9 @@ Object Protocol class, are considered classes. However, objects can override this by having a :attr:`~type.__bases__` attribute (which must be a tuple of base classes). - Another function, :attr:`~class.__base__` that is specific to CPython and also - exists in Jython and PyPy can also be used on a class inheriting from one - or more classes. + Another attribute, ``__base__`` is specific to CPython and also exists in + Jython and PyPy. It can be used on a class inheriting from one or more + classes. ``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base` in a type object. At the C level, Python has a single inheritance model @@ -432,7 +432,7 @@ Object Protocol The first user defined class that inherits either an object or derives from a class (directly or indirectly) that inherits an - object is the value returned by the :attr:`~class.__base__` function. + object is the value returned by the ``__base__`` attribute. >>> class D(B, A): pass ... @@ -440,7 +440,8 @@ Object Protocol .. impl-detail:: - Note that behavior of the ``__base__`` attribute is dependent on the :term:`CPython` implementation. + Note that behavior of the ``__base__`` attribute is dependent on the + :term:`CPython` implementation. .. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls) From 9e10d94f0feb0353b90c12a4fb21d5b679980b79 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Mon, 25 Aug 2025 11:07:10 +0300 Subject: [PATCH 15/18] Simplify __base__ attribute explanation --- Doc/c-api/object.rst | 52 +++++--------------------------------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index 64f1c7bc27cef5..dc6869055abffe 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -392,52 +392,12 @@ Object Protocol class, are considered classes. However, objects can override this by having a :attr:`~type.__bases__` attribute (which must be a tuple of base classes). - Another attribute, ``__base__`` is specific to CPython and also exists in - Jython and PyPy. It can be used on a class inheriting from one or more - classes. - - ``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base` in a - type object. At the C level, Python has a single inheritance model - that determines the memory layout of instances. There is a chain - involving base classes that contribute to the instance layout. - ``__base__`` is the base class that is involved in that chain. - When such a class takes arguments in the correct order, then starting leftmost. - - Let's look at the example cases; - - >>> class A(object): pass - ... - >>> class B(A): pass - ... - >>> class C(int): pass - ... - - The first user-defined class that either inherits from the instance - of a built-in type other than object or inherits from another user - defined class (single or multiple inheritance) that does so or in the - absence of the above class. - - >>> class D(B, A, C): pass - ... - >>> D.__base__ - - >>> - - A built-in type that is not an object or in the absence of the above class. - - >>> class D(B, A, int): pass - ... - >>> D.__base__ - - - The first user defined class that inherits either an object or - derives from a class (directly or indirectly) that inherits an - object is the value returned by the ``__base__`` attribute. - - >>> class D(B, A): pass - ... - >>> D.__base__ - + Another attribute, ``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base` + in a type object. At the C level, Python has a single inheritance model + that determines the memory layout of instances. There is a chain involving + base classes that contribute to the instance layout. ``__base__`` is the base + class that is involved in that chain. When such a class takes arguments in + the correct order, then starting leftmost. .. impl-detail:: Note that behavior of the ``__base__`` attribute is dependent on the From ed7169c00d50f6460ad290b2d57889b2eca94629 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Fri, 19 Sep 2025 21:30:47 +0300 Subject: [PATCH 16/18] Document __base__ attribute in data model reference --- Doc/c-api/object.rst | 11 ----------- Doc/reference/datamodel.rst | 11 +++++++++++ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Doc/c-api/object.rst b/Doc/c-api/object.rst index dc6869055abffe..78599e704b1317 100644 --- a/Doc/c-api/object.rst +++ b/Doc/c-api/object.rst @@ -392,17 +392,6 @@ Object Protocol class, are considered classes. However, objects can override this by having a :attr:`~type.__bases__` attribute (which must be a tuple of base classes). - Another attribute, ``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base` - in a type object. At the C level, Python has a single inheritance model - that determines the memory layout of instances. There is a chain involving - base classes that contribute to the instance layout. ``__base__`` is the base - class that is involved in that chain. When such a class takes arguments in - the correct order, then starting leftmost. - - .. impl-detail:: - Note that behavior of the ``__base__`` attribute is dependent on the - :term:`CPython` implementation. - .. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 7af3457070b84a..8f45c2e8f93b0c 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1185,6 +1185,7 @@ Special attributes single: __module__ (class attribute) single: __dict__ (class attribute) single: __bases__ (class attribute) + single: __base__ (class attribute) single: __doc__ (class attribute) single: __annotations__ (class attribute) single: __annotate__ (class attribute) @@ -1219,6 +1220,16 @@ Special attributes In most cases, for a class defined as ``class X(A, B, C)``, ``X.__bases__`` will be exactly equal to ``(A, B, C)``. + * - .. attribute:: type.__base__ + - The base class that determines the instance layout. This attribute + identifies the single base class in the inheritance chain that is + responsible for the memory layout of instances, corresponding to + :c:member:`~PyTypeObject.tp_base` at the C level. + + .. impl-detail:: + Note that behavior of the ``__base__`` attribute is dependent on the + :term:`CPython` implementation. + * - .. attribute:: type.__doc__ - The class's documentation string, or ``None`` if undefined. Not inherited by subclasses. From 20a5da78fb40567f1e7733022525ceb6cba1e5fd Mon Sep 17 00:00:00 2001 From: Furkan Onder Date: Thu, 16 Oct 2025 00:04:53 +0300 Subject: [PATCH 17/18] Document __base__ attribute with single impl-detail block Co-authored-by: Petr Viktorin --- Doc/reference/datamodel.rst | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index d37b64475f6454..a427622203905a 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1221,15 +1221,11 @@ Special attributes ``X.__bases__`` will be exactly equal to ``(A, B, C)``. * - .. attribute:: type.__base__ - - The base class that determines the instance layout. This attribute - identifies the single base class in the inheritance chain that is - responsible for the memory layout of instances, corresponding to - :c:member:`~PyTypeObject.tp_base` at the C level. - - .. impl-detail:: - Note that behavior of the ``__base__`` attribute is dependent on the - :term:`CPython` implementation. + - .. impl-detail:: + The single base class in the inheritance chain that is responsible + for the memory layout of instances. This attribute corresponds to + :c:member:`~PyTypeObject.tp_base` at the C level. * - .. attribute:: type.__doc__ - The class's documentation string, or ``None`` if undefined. Not inherited by subclasses. From ec6d7d3ad90792aa300b8d2cefb3bdde5c1483e7 Mon Sep 17 00:00:00 2001 From: furkanonder Date: Thu, 16 Oct 2025 00:18:08 +0300 Subject: [PATCH 18/18] Add blank line after documentation of __base__ attribute --- Doc/reference/datamodel.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 6ebf8584a91e26..28ef5825159cb2 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1226,6 +1226,7 @@ Special attributes The single base class in the inheritance chain that is responsible for the memory layout of instances. This attribute corresponds to :c:member:`~PyTypeObject.tp_base` at the C level. + * - .. attribute:: type.__doc__ - The class's documentation string, or ``None`` if undefined. Not inherited by subclasses.