Skip to content

Commit 9e10d94

Browse files
committed
Simplify __base__ attribute explanation
1 parent 15b8649 commit 9e10d94

File tree

1 file changed

+6
-46
lines changed

1 file changed

+6
-46
lines changed

Doc/c-api/object.rst

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -392,52 +392,12 @@ Object Protocol
392392
class, are considered classes. However, objects can override this by having
393393
a :attr:`~type.__bases__` attribute (which must be a tuple of base classes).
394394
395-
Another attribute, ``__base__`` is specific to CPython and also exists in
396-
Jython and PyPy. It can be used on a class inheriting from one or more
397-
classes.
398-
399-
``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base` in a
400-
type object. At the C level, Python has a single inheritance model
401-
that determines the memory layout of instances. There is a chain
402-
involving base classes that contribute to the instance layout.
403-
``__base__`` is the base class that is involved in that chain.
404-
When such a class takes arguments in the correct order, then starting leftmost.
405-
406-
Let's look at the example cases;
407-
408-
>>> class A(object): pass
409-
...
410-
>>> class B(A): pass
411-
...
412-
>>> class C(int): pass
413-
...
414-
415-
The first user-defined class that either inherits from the instance
416-
of a built-in type other than object or inherits from another user
417-
defined class (single or multiple inheritance) that does so or in the
418-
absence of the above class.
419-
420-
>>> class D(B, A, C): pass
421-
...
422-
>>> D.__base__
423-
<class 'C'>
424-
>>>
425-
426-
A built-in type that is not an object or in the absence of the above class.
427-
428-
>>> class D(B, A, int): pass
429-
...
430-
>>> D.__base__
431-
<class 'int'>
432-
433-
The first user defined class that inherits either an object or
434-
derives from a class (directly or indirectly) that inherits an
435-
object is the value returned by the ``__base__`` attribute.
436-
437-
>>> class D(B, A): pass
438-
...
439-
>>> D.__base__
440-
<class 'B'>
395+
Another attribute, ``__base__`` corresponds to the :c:member:`~PyTypeObject.tp_base`
396+
in a type object. At the C level, Python has a single inheritance model
397+
that determines the memory layout of instances. There is a chain involving
398+
base classes that contribute to the instance layout. ``__base__`` is the base
399+
class that is involved in that chain. When such a class takes arguments in
400+
the correct order, then starting leftmost.
441401
442402
.. impl-detail::
443403
Note that behavior of the ``__base__`` attribute is dependent on the

0 commit comments

Comments
 (0)