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

Incompatible import of "Object" in compiled UI

    XMLWordPrintable

    Details

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

      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

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

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes