[Tutor] Calling super classs __init__?
tiger12506
keridee at jayco.net
Sat Mar 22 05:11:37 CET 2008
Woah. Either you're leaving out essential info, or python got a lot more
complicated.
Firstly, super returns all base classes. How? Does it return a tuple of
them, or a container object, or is this something horribly worse such as
syntactic sugar?
It doesn't make sense for it to return a tuple, then super().__init__ would
call the init method of the tuple, not each class, so then syntactic sugar
would have to be involved. I doubt that..
A container object could use __getattr__ to magically call each of the
__init__ methods of the contained class references.
The most logical is the container object. But that leaves things open for
duplicate calls to __init__
So the container would have to keep track of the base classes it has already
called... which might be the ordered list __mro__, but those are class
specific, not global, so each super class would not know if an __init__ has
been called or not... But then again, you would need duplicate calls because
each level of super would need different initiation.
I apologize. Would you care to explain this a little more technically?
Specific and accurate are better than translated into layman's terms. I've
been with python for a while now. thanks.
>Actually, super returns all base classes, all in it's own time.
>
>Basically, every class has a member __mro__, that contains a
>consistently ordered list of classes.
>
>super needs the class from where it is being called to locate the right
>place in the __mro__ and to hand you a wrapper around self for the next
>base class in this list.
>
>This way, if all classes use super, they can cooperativly call all
>implementations of a given method.
>
>That's the theory. In practice there are a number of pitfalls which
>makes super problematic. ;)
>
>Andreas
More information about the Tutor
mailing list