<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">Hi Phil, Hi Baz, Hi List,<br><br></div><div class="gmail_quote">to pitch in my two cents:<br><br></div><div class="gmail_quote">yes, I can just write:<br><br>
class A(object):<br></div><div class="gmail_quote"> def sizeHint(self):<br></div><div class="gmail_quote"> print(self.parent())<br></div><div class="gmail_quote"> super().sizeHint()<br><br></div><div class="gmail_quote">
class B(A, QLabel):<br></div><div class="gmail_quote"> pass<br><br></div>it works OK, but it is actually really weird code. <br></div><div class="gmail_extra">In class A I am calling methods which are not in my base class.<br>
Well, it still works, so I shouldn't complain (I simply did<br>not get the idea of writing that, since, well, what is it<br>supposed to mean to call a method of a, well, non-existing<br>base class?)<br><br></div><div class="gmail_extra">
Yes I know, I am just nitpicking, it would just be cool to be<br>able to write nice code... I tried to find a situation in which this<br>triggers a problem, couldn't find one yet but well. So, this<br>is why I think my patch is still cool, as it allows for nicer code.<br>
<br></div><div class="gmail_extra">Btw, the discussion whether class A(B, C), or class A(C, B) is<br>prettier is, well, weird. This is like discussing whether 2 ** n or<br></div><div class="gmail_extra">n ** 2 is prettier. Neither is, it's just different code.<br>
<br>That said, it should be stated clearly somewhere in the PyQt<br>documentation: ALLWAYS PUT YOUR Qt CLASS LAST IN THE<br>INHERITANCE LIST! Why that? Well, PyQt is not cooperative,<br>meaning it is not calling super, so it does not honor the method<br>
resolution order. By putting the Qt classes last in the inheritance<br>list, all Qt classes will always end up in the end of the MRO, so<br>be called last. Then it simply doesn't matter that they in turn <br></div><div class="gmail_extra">
don't call super, since, well, the MRO is at its end anyways.<br><br></div><div class="gmail_extra">What you don't ever want is to have is a situation in which a<br>non-Qt class ends up in the middle of the MRO chain. An example<br>
would be:<br><br></div><div class="gmail_extra">class Mixin(QObject):<br></div><div class="gmail_extra"> pass<br><br>class B(QWidget, Mixin):<br></div><div class="gmail_extra"> pass<br><br></div><div class="gmail_extra">
Then the MRO is B, QWidget, Mixin, QObject. You must be<br>really lucky to get your methods in Mixin called properly.<br><br></div><div class="gmail_extra">In PyQt5, I read, __init__ does call super. While this might<br>be nice, it is actually unnecessary. The example in the docs<br>
(<a href="http://pyqt.sourceforge.net/Docs/PyQt5/multiinheritance.html">http://pyqt.sourceforge.net/Docs/PyQt5/multiinheritance.html</a>)<br></div><div class="gmail_extra">actually works perfect with PyQt4 already if one just swaps<br>
</div><div class="gmail_extra">QObject and Age in the class definition of Person.<br><br></div><div class="gmail_extra">Greetings<br><br>Martin<br></div></div>