On Wed, Jun 26, 2013 at 5:54 PM, Steven D'Aprano <steve+comp.lang.pyt...@pearwood.info> wrote: > No. But "the current object" is not Base1, but an instance of Derived, > and Base2 *is* an ancestor of Derived. Perhaps if I had said "self" > instead of current object, you wouldn't have made this error. If so, I > apologise for confusing you.
If I am reading a class definition and see the code super().__init__(), and I am not familiar with super() and do not bother to go look it up in the docs because it looks "obvious" (or perhaps I have read a tutorial that simply mentions that super() is used to call methods from a superclass and elides over the details) -- my assumption is not going to be that super() is looking into superclasses relative to the class of self, but more simply that super() is looking into superclasses relative to the class that I'm currently reading. Why? Because that's the way that "super" works in every other language I know of that has it. Java: super looks depth-first from the contextual class (no multiple inheritance allowed) Ruby: super looks depth-first from the contextual class (no multiple inheritance allowed) Objective-C: super looks depth-first from the contextual class (no multiple inheritance allowed) Perl 5: by default, super looks depth-first from the contextual class (multiple inheritance IS allowed; the C3 linearization (MRO) CAN be used, but it must first be explicitly enabled with a pragma directive) Now if you're coming from Java, Ruby, or Objective-C and reading a Python super() statement, then hopefully you will stop and think, "Hey, wait a minute. [Other language] doesn't have multiple inheritance and Python does, so how does super() work here?" More likely though you're not even thinking about multiple inheritance when you read that statement, and you just assume that it works exactly like the super keyword that you're used to, and you move on. -- http://mail.python.org/mailman/listinfo/python-list