Really stupid question regarding PEP 252 and type/class unification

Guido van Rossum guido at python.org
Wed Aug 29 23:20:54 EDT 2001


russell_turpin at hotmail.com (Russell Turpin) writes:

> So .. do types support multiple inheritance? I would assume
> they don't, i.e., that the following generates an error:
> 
>     class Mosaic(dictionary, int):
>         pass
> 
> After all, a mosaic can't have two types of default attribute
> (value). But then, what happens in the next step, when classes
> and types are truly unified? That one has me scratching my 
> head.

Indeed, you can't subclass from multiple built-in types.  But you can
subclass from multiple user-defined classes that derive from the same
built-in type.  E.g. this is fine:

class B(list): pass
class C(list): pass
class D(B, C): pass

The complete rule that explains what combinations are cool is a bit
complex, but a simplified version is easy enough to remember: you can
multiply inherit from user-defined new-style classes as long as they
all derive from the same built-in type, or from object.

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



More information about the Python-list mailing list