spyder-ide / qtpy

Provides an uniform layer to support PyQt5, PySide2, PyQt6, PySide6 with a single codebase
MIT License
987 stars 153 forks source link

Hijacked PyQt types are not returned from native Qt APIs #502

Open ivany4 opened 2 weeks ago

ivany4 commented 2 weeks ago

QtPy 2.4.2 has integrated this PR: https://github.com/spyder-ide/qtpy/pull/461, which swaps QToolbar and QAction types with custom subclasses. This introduced a new problem that instances returned from Qt no longer pass instance checks.

E.g.:

from qtpy import QtWidgets

app = QtWidgets.QApplication([])
window = QtWidgets.QMainWindow()
new_toolbar = window.addToolBar('Toolbar title')
assert isinstance(new_toolbar, QtWidgets.QToolBar)

This will pass in QtPy 2.4.1 and will fail with QtPy 2.4.2. It now requires to check against true PyQt classes, e.g. assert isinstance(new_toolbar, PyQt5.QtWidgets.QToolBar)

By extension, returned instances will have different behavior from the manually created ones