[issue20518] multiple inheritance + C extension = possibly unexpected __base__

Eric Snow report at bugs.python.org
Thu Feb 6 05:47:45 CET 2014


Eric Snow added the comment:

So to restate, where some class Spam inherits from multiple classes and at least one was written in C, Spam.__base__ may have an unexpected value.

> So, to conclude: it is sometimes not possible to use python
> cooperative multiple inheritance if C base classes are involved. This
> is a bummer.

Be careful not to muddy the waters here by obscuring the problem you are describing (regarding __base__) with the challenges of making multiple inheritance work.  Multiple inheritance with classes that don't cooperate in your hierarchy is tricky, but solveable and is simply the nature of the beast.  To move this issue forward I recommend simply focusing on how __base__ (and its use) could be improved.

I think part of the problem is that the metaclass of PyQt4 uses the __base__ class attribute instead of the MRO...

<aside>
Cooperative multiple inheritance is all about the classes involved cooperating.  You already indicated that the QT classes do not cooperate.  To work around this you could wrap QT objects with proxies that *do* cooperate in your multiple inheritance scheme.  Alternately you could fiddle around in __init__ to make it work.  Raymond Hettinger had a great talk on this topic at Pycon 2012 (or was it 2013) that would be worth checking out.  I remember him discussing strategies for fitting uncooperative classes into a multiple inheritance hierarchy.
</aside>

----------
components: +Extension Modules -Interpreter Core
nosy: +eric.snow
title: Weird behavior with multiple inheritance when C classes involved -> multiple inheritance + C extension = possibly unexpected __base__

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue20518>
_______________________________________


More information about the Python-bugs-list mailing list