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

Incompatible import of "Object" in compiled UI

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • None
    • 5.15.1
    • PySide
    • None
    • Ubuntu 20.04, Python 3.8.5
    • Linux/X11
    • 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

      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">
       <class&gt;Form</class&gt;
       <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

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

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: