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 |
346399,2 | uic/Python: Add comments for mypy to ignore star imports | 6.1 | qt/qtbase | Status: MERGED | +2 | 0 |
346400,3 | uic/Python: Add comments for mypy to ignore star imports | tqtc/lts-5.15 | qt/tqtc-qtbase | Status: MERGED | +2 | 0 |
346483,3 | uic/Python: Add comments for mypy to ignore star imports | dev | qt/qtbase | Status: MERGED | +2 | 0 |
346517,2 | uic: Update qclass_lib_map.h | dev | qt/qtbase | Status: MERGED | +2 | 0 |
346518,13 | uic: No longer generate star imports in Python | dev | qt/qtbase | Status: MERGED | +2 | 0 |
346683,8 | Add a testing tool for uic | dev | pyside/pyside-setup | Status: MERGED | +2 | 0 |
346864,2 | Add a testing tool for uic | tqtc/lts-5.15 | pyside/tqtc-pyside-setup | Status: MERGED | +2 | 0 |
346964,2 | Adapt version of the uic testing tool | tqtc/lts-5.15 | pyside/tqtc-pyside-setup | Status: MERGED | +2 | 0 |
347016,8 | uic: Extract a base class for WriteIncludes | dev | qt/qtbase | Status: MERGED | +2 | 0 |
349265,4 | uic: Add further widgets to class lib map | dev | qt/qtbase | Status: MERGED | +2 | 0 |
389639,2 | uic/Python: Import base class for flag values | dev | qt/qtbase | Status: MERGED | +2 | 0 |
389914,1 | uic/Python: Import base class for flag values | 6.2.3 | qt/qtbase | Status: ABANDONED | +2 | 0 |
389915,2 | uic/Python: Import base class for flag values | 6.3 | qt/qtbase | Status: MERGED | +2 | 0 |
389916,2 | uic/Python: Import base class for flag values | 6.2 | qt/qtbase | Status: MERGED | +2 | 0 |