interactive help on the base object

Chris Angelico rosuav at gmail.com
Tue Dec 10 00:44:48 EST 2013


On Tue, Dec 10, 2013 at 4:27 PM, Alan Bawden
<alan at scooby-doo.csail.mit.edu> wrote:
> Chris Angelico <rosuav at gmail.com> writes:
>
>> On Mon, Dec 9, 2013 at 6:31 PM, Alan Bawden
>> ...
>> How does that work, exactly? How do you have a class inherit
>> (ultimately) from itself, and how does that impact the component class
>> list?
>
> How does it work "exactly"?  You're asking me about a feature I never
> made use of, in a system I have no source for, and that I haven't used
> in over 25 years!  If it wasn't mentioned in a parenthetical comment in
> the 32-year-old documentation I still have on my bookshelf (Lisp Machine
> Manual, 4th edition, July 1981, blue cover), I wouldn't trust my own
> memory that such a thing ever even existed.
>
> So you're not getting anything "exact" here!

LOL!

> I have no idea exactly how it worked, but imagine something that walked
> the superclass graph _as_ _if_ it was a tree, collected classes in some
> order, and that just skips any class it encounters for the second time.
> That results in _some_ linear ordering of all the classes you can reach
> from the starting class.  Now use that.

Ow, that sounds a bit... weird. I think I prefer an acyclic graph for
inheritance! A few weirdnesses are necessary for bootstrapping -
type(object) is type, type(type) is type, and type.__bases__ =
(object,) - but normally every type should be created before all
instances of it, and every superclass before all its subclasses.

But of course, *multiple* inheritance is always weird. I've worked in
some detail with four systems (C++, Python, Pike, Java), and they're
all quite different in how they handle MI. Java says "There is no
MI... but you can implement multiple interfaces". C++ says "There is
MI and there is virtual MI, and if one of them doesn't do your head
in, the other will". Python says "It's all about method resolution,
instance data is separate, so make sure everything cooperates". Pike
says "If both parents define a method, super() will return an array of
methods, but that's okay because arrays are callable". It's a
fundamentally tricky problem, largely because every real-world analogy
we can muster is going to end up looking more like composition than
inheritance (a guided missile is-a bomb and is-a rocket, but it's just
as valid to say it is-a rocket and it has-a bomb).

ChrisA



More information about the Python-list mailing list