Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1404

Incompatible import of "Object" in compiled UI



    • Type: Bug
    • Status: Reported
    • Priority: Not Evaluated
    • Resolution: Unresolved
    • Affects Version/s: 5.15.1
    • Fix Version/s: None
    • Component/s: PySide
    • Labels:
    • Environment:
      Ubuntu 20.04, Python 3.8.5
    • Platform/s:


      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".


      1. Don't upgrade to PySide2 5.15.1.
      2. 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">
       <widget class="QWidget" name="Form">
       <property name="geometry">
       <property name="windowTitle">
       <layout class="QVBoxLayout" name="verticalLayout">
       <widget class="QLabel" name="label">
       <property name="text">
       <string>Hello, World!</string>

      Could you either stop using import * in the new places, or use _all_ to exclude Object from at least two of the three modules?


          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.



              crmaurei Cristian Maureira-Fredes
              donkirkby Don Kirkby
              0 Vote for this issue
              3 Start watching this issue



                  Gerrit Reviews

                  There are no open Gerrit changes