Details
-
Bug
-
Resolution: Done
-
Not Evaluated
-
None
-
5.15.1
-
None
-
Ubuntu 20.04, Python 3.8.5
-
-
ac95326ad46fbff310ad25baaf96262d851509c1 (qt/qtbase/dev) 5a7d1b2a032bb1f7befd271c24642dc36d8b4d4e (qt/qtbase/6.1) 3c2418cdc35d7f45c2ddc35698b0e7f31fc61fe2 (qt/tqtc-qtbase/5.15)
Description
Thanks for publishing this great GUI framework for Python.
Mypy complains about the import statements generated by the new version of pyside2-uic. The error message from mypy is:
Incompatible import of "Object" (imported name has type "Type[PySide2.QtGui.Object]", local name has type "Type[PySide2.QtCore.Object]")
I wrote a very small UI file, and compiled it with pyside2-uic version 5.15.0. Here's what the imports looked like:
from PySide2.QtCore import (QCoreApplication, QDate, QDateTime, QMetaObject,
QObject, QPoint, QRect, QSize, QTime, QUrl, Qt)
from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont,
QFontDatabase, QIcon, QKeySequence, QLinearGradient, QPalette, QPainter,
QPixmap, QRadialGradient)
from PySide2.QtWidgets import *
Those imports work fine, and don't cause any complaints from mypy. Now here's the imports from the same UI file, compiled with pyside2-uic version 5.15.1:
from PySide2.QtCore import *
from PySide2.QtGui import *
from PySide2.QtWidgets import *
It's much tidier, but the import * statements cause conflicts for mypy when different things are imported with the same name of "Object".
Workarounds
- Don't upgrade to PySide2 5.15.1.
- Tell mypy to shut up about the generated code:
from PySide2.QtCore import *
from PySide2.QtGui import * # type: ignore
from PySide2.QtWidgets import * # type: ignore
Here's the full UI file I used to show the problem:
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Form</class> <widget class="QWidget" name="Form"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>400</width> <height>300</height> </rect> </property> <property name="windowTitle"> <string>Form</string> </property> <layout class="QVBoxLayout" name="verticalLayout"> <item> <widget class="QLabel" name="label"> <property name="text"> <string>Hello, World!</string> </property> </widget> </item> </layout> </widget> <resources/> <connections/> </ui>
Could you either stop using import * in the new places, or use _all_ to exclude Object from at least two of the three modules?
Attachments
Issue Links
- resulted from
-
PYSIDE-1287 pyside2-uic: missing imports QGradient, QLocale, QRectF
- Closed
- resulted in
-
PYSIDE-1773 uic doesn't import QAbstractItemView for QTableView/QTreeView EditTriggers
- Closed
For Gerrit Dashboard: PYSIDE-1404 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
346477,5 | WIP: Re-add uic .pro files | dev | qt/qtbase | Status: NEW | -2 | 0 |