Martin Teichmann added the comment: I've been working a bit on a solution to this issue, one proposal is in the attached patch. The patch adds a new flag to tp_flags, called Py_TPFLAGS_SOLID, which marks a class as being solid, i.e. its memory layout is incompatible with its parent layout. C classes can then set this flag, and cpython will assure that no incompatible classes are in the same inheritance graph.
Other solutions are certainly thinkable: Eric proposed one should use the MRO instead of __base__. This is a great idea, why is cpython itself not doing it? Instead of traversing the inheritance graph trying to find the solid base, one could simply iterate over the MRO. In order to illustrate where the actual problem lies, here another example: ========================================= rom PyQt4.QtCore import QObject, QTimer, QTimerEvent # QObject is the parent of QTimer class Mixin(QObject): # this overwrites QObject.timerEvent def timerEvent(self, e): print('mixed in') super().timerEvent(e) class B(Mixin, QTimer): pass class C(QTimer, Mixin): pass event = QTimerEvent(0) b = B() try: b.timerEvent(event) except Exception as e: print(e) print('---------') c = C() c.timerEvent(event) ========================================= I'm writing a mixin class, that overwrites a method from QObject. In the end I am calling this method (normally that's done from within PyQt4). For class B, this mixing in works properly, my code is executed, but then I am getting an exception: PyQt4 had made b and instance of QObject, not QTimer, since this is where the __base__ is pointing to. For class C, my code is never called because PyQt4 is not cooperating. Sure, I could write wrapper classes for every Qt class that I want to mix into, but what would be the point of a mixin class then? I hope I made my problem a bit clearer. ---------- Added file: http://bugs.python.org/file33997/patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue20518> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com