[Python-Dev] type categories

Guido van Rossum guido@python.org
Fri, 13 Sep 2002 00:37:57 -0400

> > Why do keep arguing for inheritance?  (a) the need to deny inheritance
> > from an interface, while essential, is relatively rare IMO, and in
> > *most* cases the inheritance rules work just fine; (b) having two
> > separate but similar mechanisms makes the language larger.
> > 
> > For example, if we ever are going to add argument type declarations to
> > Python, it will probably look like this:
> > 
> >     def foo(a: classA, b: classB):
> >         ...body...
> I'm curious, and I don't recall having seen anything about this: why
> wouldn't we simply use attributes to hold this information, like
> __slots__?  After all, attributes get inherited, too, and there's no
> need to pretzel the syntax.  Using attributes IMO would make it easier
> to handle the case where derived classes need to mangle type and
> interface declarations.

That's exactly what Zope does with the __inherits__ attribute.

But it's got limitations: there's only one __inherits__ attribute, so
it isn't automatically merged properly on multiple inheritance, and
adding one new interface to it means you have to copy or reference the
base class __inherits__ attribute.

Also, __slots__ is provisional.  The plan is for this to eventually
get nicer syntax (when I get over my fear of adding new keywords :-).

--Guido van Rossum (home page: http://www.python.org/~guido/)