[Python-Dev] Multiple inheritance from builtin (C) types [still] supported in Python3?

Guido van Rossum guido at python.org
Mon Apr 28 20:36:01 CEST 2014


Antoine's example works because list inherits from object. The more general
rule "compatible layout" only allows the rarest of cases to work --
basically the two classes involved must have a common base class and one of
the classes must not add any C-level fields to that base class's layout. I
would never count on this except in cases where this possibility is
documented (e.g. when one class is designed to be a mix-in for the other).


On Mon, Apr 28, 2014 at 11:24 AM, Antoine Pitrou <solipsis at pitrou.net>wrote:

> On Mon, 28 Apr 2014 20:45:48 +0300
> Paul Sokolovsky <pmiscml at gmail.com> wrote:
> >
> > So, is that it, or disjoint native types are supported as bases
> > somehow? Also, would someone know if a class-subclass case happens for
> > example in stdlib?
>
> Well, for instance this trivial example works:
>
> >>> class C(list, object): pass
> ...
> >>>
>
> Basically, if two classes have compatible layouts, you can inherit from
> both at once.
>
> Regards
>
> Antoine.
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Dev at python.org
> https://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> https://mail.python.org/mailman/options/python-dev/guido%40python.org
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-dev/attachments/20140428/835689d9/attachment.html>


More information about the Python-Dev mailing list