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

QByteArray.data return type hint is incorrect

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Incomplete
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 6.9.2
    • Type hints
    • None
    • All

      QByteArray.data() is incorrectly type hinted.

      As far as I can tell, QByteArray.data in python can only return a bytes object.

      https://github.com/pyside/pyside-setup/blob/ffcd3ad810feba486fd6f4001ca5c1ddad2731d5/sources/pyside6/PySide6/QtCore/typesystem_core_common.xml#L2169C1-L2171C22

      https://github.com/pyside/pyside-setup/blob/ffcd3ad810feba486fd6f4001ca5c1ddad2731d5/sources/pyside6/PySide6/glue/qtcore.cpp#L903C1-L905C28

      The return type hint should reflect this.

      Current (incorrect) type hint

      def data(self, /) -> bytes | bytearray | memoryview: ... 

      Correct type hint

      def data(self, /) -> bytes: ... 

      As discussed in the comments, other classes may handle conversion from C++ to Python differently.

      As far as I can tell nothing inherits QByteArray so there is no reason to have a broader return type than the implementation.

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

            crmaurei Cristian Maureira-Fredes
            gentlegiantjgc J C
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes