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

Inconsistent type check for [bytes, bytearray, memoryview] in QByteArray

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4: Low
    • 6.8.0, 6.7.3
    • 6.7.2
    • Type hints
    • None
    • macOS
    • 19c693497 (dev), d63b1bd81 (6.7)

    Description

      QByteArray Constructor - it does work as expected.

      from PySide6.QtCore import QByteArray
      rawbytes = b'aaaaaaaaaaaa'
      print("rawbytes type =",type(rawbytes))
      qbytearray = QByteArray(rawbytes)
      print(qbytearray.data())
      

      QByteArray static method fromRawBytes:

      from PySide6.QtCore import QByteArray
      rawbytes = b'aaaaaaaaaaaa'
      print("rawbytes type =",type(rawbytes))
      qbytearray = QByteArray.fromRawData(rawbytes, len(rawbytes))
      

      Output:

      rawbytes type = <class 'bytes'>
      

      Traceback:

      ---------------------------------------------------------------------------
      ValueError                                Traceback (most recent call last)
      Cell In[18], line 4
            2 rawbytes = b'aaaaaaaaaaaa'
            3 print("rawbytes type =",type(rawbytes))
      ----> 4 qbytearray = QByteArray.fromRawData(rawbytes, len(rawbytes))
      
      ValueError: 'PySide6.QtCore.QByteArray.fromRawData' called with wrong argument values:
        PySide6.QtCore.QByteArray.fromRawData(b'aaaaaaaaaaaa', 12)
      Found signature:
        PySide6.QtCore.QByteArray.fromRawData(Union[bytes, bytearray, memoryview], int)
      

      Converting bytes to bytearray doesn't help:

      from PySide6.QtCore import QByteArray
      rawbytes = b'aaaaaaaaaaaa'
      barray = bytearray(rawbytes)
      print("barray type =",type(barray))
      qbytearray = QByteArray.fromRawData(barray, len(barray))
      
      ValueError                                Traceback (most recent call last)
      Cell In[20], line 5
            3 barray = bytearray(rawbytes)
            4 print("barray type =",type(barray))
      ----> 5 qbytearray = QByteArray.fromRawData(barray, len(barray))
      
      ValueError: 'PySide6.QtCore.QByteArray.fromRawData' called with wrong argument values:
        PySide6.QtCore.QByteArray.fromRawData(bytearray(b'aaaaaaaaaaaa'), 12)
      Found signature:
        PySide6.QtCore.QByteArray.fromRawData(Union[bytes, bytearray, memoryview], int)
      

      Attachments

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

        Activity

          People

            shpremna Shyamnath Premnadh
            mq Michal Kurtys
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes