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

Improve numpy type hinting

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3: Somewhat important
    • 6.10.0
    • 6.10.0
    • Type hints
    • None
    • All
    • a33f25772 (dev), 1dc631efe (6.9)

    Description

      When adding a function with a PySequence and a numpy overload (specified by PyArrayObject, see https://codereview.qt-project.org/c/pyside/pyside-setup/+/642868 ), the PyArrayObject is mapped to

      "PyArrayObject": ArrayLikeVariable(typing.Any),  # numpy
      

      by sources/shiboken6/shibokenmodule/files.dir/shibokensupport/signature/mapping.py:234, leading to

         @typing.overload
          def __init__(self, list: collections.abc.Iterable, /, parent: PySide6.QtCore.QObject | None = ...) -> None: ...
          @typing.overload
          def __init__(self, data: collections.abc.Sequence[typing.Any], /, parent: PySide6.QtCore.QObject | None = ...) -> None: ...
      

      This causes an error in sources/pyside6/tests/pysidetest/mypy_correctness_test.py :

      /QtCore.pyi:3457: error: Overloaded function signature 2 will
      never be matched: signature 1's parameter type(s) are the same or broader
      [overload-cannot-match]
              def __init__(self, data: collections.abc.Sequence[typing.Any], /, ...
      Found 1 error in 1 file (checked 10 source files)
      

      For this, the type hint for numpy needs to be more specific (see also https://numpy.org/devdocs/reference/typing.html ).

      Note though it is possible to build PySide without numpy (--disable-numpy-support), and importing numpy directly can be costly.

      Attachments

        Issue Links

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

          Activity

            People

              ctismer Christian Tismer
              kleint Friedemann Kleint
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes