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

Typing for sequences and callables is broken

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Not Evaluated
    • None
    • 6.9.0
    • Type hints
    • None
    • c907725a5 (dev)

    Description

      Type hints generated by pyside6-genpyi (or shiboken6-genpyi) include references to `collections.abc.Sequence`. Example from QtWidgets.pyi:

       

      class QApplication(PySide6.QtGui.QGuiApplication):
          [...]
          @staticmethod
          def setFont(arg__1: PySide6.QtGui.QFont | str | collections.abc.Sequence[str], /, className: bytes | bytearray | memoryview | None = ...) -> None: ... 

      However, the import for collections.abc is missing. Only collections is imported:

       

       

      # Copyright (C) 2022 The Qt Company Ltd.
      # SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
      from __future__ import annotations
      """
      This file contains the exact signatures for all functions in module
      PySide6.QtWidgets, except for defaults which are replaced by "...".
      
      # mypy: disable-error-code="override, overload-overlap"
      """
      
      # Module `PySide6.QtWidgets`
      
      import PySide6.QtWidgets
      import PySide6.QtCore
      import PySide6.QtGui
      import os
      import enum
      import typing
      import collections
      from PySide6.QtCore import Signal, SignalInstance
      from shiboken6 import Shiboken 

      This means that type checkers such as basedpyright might be unable to resolve the Sequence type.

       

      See:

      The first argument is recognized as "Unknown" by basedpyright and "Any" by Pylance.

      Replacing the import with the proper collections.abc fixes all errors.

      I guess the proper place to fix this would be here: https://github.com/pyside/pyside-setup/blob/e55bad3c11de793828fb1bdb503d1631c153a488/sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/lib/pyi_generator.py#L244

      Attachments

        Issue Links

          For Gerrit Dashboard: PYSIDE-3092
          # Subject Branch Project Status CR V

          Activity

            People

              ctismer Christian Tismer
              mtnpke Philipp Kerling
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes