On 16/07/19 12:13 PM, Joseph L. Casale wrote:
I am trying to find explicit documentation on the initialization logic for a
Base class when multiple exist. For the example in the documentation at
https://docs.python.org/3/tutorial/classes.html#multiple-inheritance,
if Base1 and Base2 both themselves inherited from the same base class,
only Base1 would call __init__ on the subclass, Base2 would not. While
I know this from experience, I need to locate actual documentation, does
Anyone know if it exists?
There are two "initialisation" 'events', or two points-in-time:
1 import - when the various namespaces are constructed
2 execution - when a method is called.
(am assuming the latter)
That document describes MRO as "search for attributes inherited from a
parent class as depth-first, left-to-right, not searching twice in the
same class where there is an overlap in the hierarchy"; and goes on to
say "all classes inherit from object, so any case of multiple
inheritance provides more than one path to reach object. To keep the
base classes from being accessed more than once, the dynamic algorithm
linearizes the search order in a way that preserves the left-to-right
ordering specified in each class, that calls each parent only once, and
that is monotonic".
Add those together with the idea of 'search' - when the search algorithm
is searching for something, eg which super().__init__(), once it has
'found' the entity (which may actually be 'the first such entity' or
'the first way to find this entity' in the 'diamond' case), it STOPS
looking! Accordingly, avoiding a duplicate execution problem.
Does that satisfy the question?
--
Regards =dn
--
https://mail.python.org/mailman/listinfo/python-list