Goodies Goodies - 10 months ago 110
Python Question

PyQt5 non-default parameter after default parameter?

I don't do a lot of work in GUI's, but I've decided to move from occasionally using PyQt4 to PyQt5. My IDE is giving me warnings about some of the

functions, particularly QWidget and QMainWindow.

If you look at the IntelliSense'd parameters, you'll see that the
parameter has a default and the
does not. The IDE tells me that
is unfilled, but when I don't provide it, nothing happens. Why is this happening?

I'm using Python 3.5.


Answer Source

The correct signature is this:

QMainWindow(parent: QWidget = None,
            flags: Union[Qt.WindowFlags, Qt.WindowType] = Qt.WindowFlags())

So it looks like the IntelliSense in your IDE does not know how to parse type-hints properly (or at all). There are only two arguments: parent and flags, both of which have defaults.

(NB: you should never use self.__class__ with super as it can lead to an infinite recursion under certain circumstances. Always pass in the subclass as the first argument - unless you're using Python 3, in which case you can omit all the arguments).