[PyQt] Not understanding instanceof() in this situation

J Barchan jnbarchan at gmail.com
Tue Jul 17 16:45:00 BST 2018

Sorry if this turns out to be a general question about Python's instanceof()
rather than specifically PyQt.....

For debugging leaks (in a simple fashion) I am walking
QtWidgets.QApplication.allWidgets() looking at those whose parent() is None.

I come across one I wish to ignore.  PyCharm debugger shows its class as
__main__.Main.  My code has:

class Main(QtWidgets.QMainWindow):

if __name__ == '__main__':
    mainWindow = Main()

So in my checker I try:

from main.py import Main
if isinstance(widget, Main): ...

But this returns False on the widget.  I discovered I can just check
instead for isinstance(widget, QtWidgets.QMainWindow), so I'm OK and that's
better anyway.

But I don't understand why it is not an instance of my Main given that is
derived from QtWidgets.QMainWindow?  Could someone patiently enlighten me?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20180717/6d71c1de/attachment.html>

More information about the PyQt mailing list