<font size=2 face="sans-serif">Hi there, </font>
<br>
<br><font size=2 face="sans-serif">thanks - I guess I wasn't really aware
of the super-workings with multiple inheritance (a good occasion to re-read
Hettinger's nlog entry on this...).</font>
<br><font size=2 face="sans-serif">Things worked just fine though with
PyQt4, so this caused some confusion.</font>
<br>
<br><font size=2 face="sans-serif">Cheers</font>
<br><font size=2 face="sans-serif">Sebastian</font>
<br>
<br>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">Von:      
 </font><font size=1 face="sans-serif">Baz Walter <bazwal@ftml.net></font>
<br><font size=1 color=#5f5f5f face="sans-serif">An:      
 </font><font size=1 face="sans-serif">pyqt@riverbankcomputing.com</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Datum:      
 </font><font size=1 face="sans-serif">09.12.2016 20:51</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Betreff:    
   </font><font size=1 face="sans-serif">Re: [PyQt] Multiple
Inheritance with PyQt5 on python 2</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Gesendet von:    
   </font><font size=1 face="sans-serif">"PyQt"
<pyqt-bounces@riverbankcomputing.com></font>
<br>
<hr noshade>
<br>
<br>
<br><tt><font size=2>On 09/12/16 12:22, Sebastian Eckweiler wrote:<br>
> Hi there,<br>
><br>
> I've just read through<br>
> </font></tt><a href=http://pyqt.sourceforge.net/Docs/PyQt5/multiinheritance.html><tt><font size=2>http://pyqt.sourceforge.net/Docs/PyQt5/multiinheritance.html</font></tt></a><tt><font size=2>.<br>
> I'm using a self-built PyQt5 for Python 2 on Windows - and it seems
I<br>
> can't get multiple inheritance to work:<br>
><br>
> class SomeClass(object):<br>
><br>
>     def __init__(self, attr):<br>
>         self.attr = attr<br>
><br>
> class AnotherDialog(QtWidgets.QDialog, SomeClass):<br>
><br>
>     def __init__(self, parent=None):<br>
>         #super(AnotherDialog, self).__init__(parent)
# tested this was<br>
> well<br>
>         QtWidgets.QDialog.__init__(self, parent)<br>
>         SomeClass.__init__(self, 1)<br>
><br>
><br>
> app = QtWidgets.QApplication([])<br>
> dlg = AnotherDialog()<br>
><br>
> This always results in<br>
><br>
> TypeError: __init__() takes exactly 2 arguments (1 given)<br>
><br>
> is there a workaround for this?<br>
<br>
The signature of SomeClass has one required positional argument. If you
<br>
use super, how is it going to get that argument if you don't pass it to
<br>
the AnotherDialog constructor?<br>
<br>
The docs you linked to explained that you should use keyword arguments.
<br>
So one way to resolve the issue would be like this:<br>
<br>
     class SomeClass(object):<br>
         def __init__(self, attr=1, **kwargs):<br>
             super(SomeClass, self).__init__(**kwargs)<br>
             self.attr = attr<br>
<br>
     class AnotherDialog(QtWidgets.QDialog, SomeClass):<br>
         def __init__(self, parent=None, **kwargs):<br>
             super(AnotherDialog, self).__init__(parent,
**kwargs)<br>
<br>
Or, less flexibly, perhaps like this:<br>
<br>
     class SomeClass(object):<br>
         def __init__(self, attr):<br>
             super(SomeClass, self).__init__()<br>
             self.attr = attr<br>
<br>
     class AnotherDialog(QtWidgets.QDialog, SomeClass):<br>
         def __init__(self, parent=None):<br>
             super(AnotherDialog, self).__init__(parent,
attr=1)<br>
<br>
Without super, put the mixin first:<br>
<br>
     class SomeClass(object):<br>
         def __init__(self, attr):<br>
             self.attr = attr<br>
<br>
     class AnotherDialog(SomeClass, QtWidgets.QDialog):<br>
         def __init__(self, parent=None):<br>
             SomeClass.__init__(self, 1)<br>
             QtWidgets.QDialog.__init__(self,
parent)<br>
<br>
_______________________________________________<br>
PyQt mailing list    PyQt@riverbankcomputing.com<br>
</font></tt><a href=https://www.riverbankcomputing.com/mailman/listinfo/pyqt><tt><font size=2>https://www.riverbankcomputing.com/mailman/listinfo/pyqt</font></tt></a>
<br>