diff --git a/CHANGELOG.md b/CHANGELOG.md index 6352036e..8b68289d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Added * [#138](https://github.com/python-qt-tools/PyQt5-stubs/pull/138) update to PyQt5 5.15.3 * [#144](https://github.com/python-qt-tools/PyQt5-stubs/pull/144) add `QTreeWidgetItem.__lt__()` to allow sorting of items in a QTreeWidget +* [#143](https://github.com/python-qt-tools/PyQt5-stubs/pull/143) make `bytes(QByteArray())` valid by incorrectly adding `.__bytes__()` until a proper solution is developed upstream ## 5.15.2.0 diff --git a/PyQt5-stubs/QtCore.pyi b/PyQt5-stubs/QtCore.pyi index 5a53e997..e430ea9a 100644 --- a/PyQt5-stubs/QtCore.pyi +++ b/PyQt5-stubs/QtCore.pyi @@ -3746,6 +3746,15 @@ class QByteArray(sip.simplewrapper): @typing.overload def __init__(self, a: typing.Union['QByteArray', bytes, bytearray]) -> None: ... + # TODO: this is a lie... :| it is actually the buffer C-api that is + # implemented. see the discussions below and correct this when a + # proper fix is available. + # + # https://github.com/python-qt-tools/PyQt5-stubs/pull/143 + # https://github.com/python/typing/issues/593 + # https://bugs.python.org/issue27501 + def __bytes__(self) -> bytes: ... + @staticmethod def fromBase64Encoding(base64: typing.Union['QByteArray', bytes, bytearray], options: typing.Union['QByteArray.Base64Options', 'QByteArray.Base64Option'] = ...) -> 'QByteArray.FromBase64Result': ... def isLower(self) -> bool: ... diff --git a/stubtest.allowlist.to_review b/stubtest.allowlist.to_review index 9cd83616..cd96ad59 100644 --- a/stubtest.allowlist.to_review +++ b/stubtest.allowlist.to_review @@ -1,6 +1,7 @@ PyQt5.QtBluetooth.QBluetoothDeviceInfo.Field.__new__ PyQt5.QtCore.QAbstractItemModel.CheckIndexOption.__new__ PyQt5.QtCore.QByteArray.Base64DecodingStatus.__new__ +PyQt5.QtCore.QByteArray.__bytes__ PyQt5.QtCore.QCalendar.System.__new__ PyQt5.QtCore.QCborKnownTags.__new__ PyQt5.QtCore.QCborSimpleType.__new__ diff --git a/tests/qbytearray.py b/tests/qbytearray.py new file mode 100644 index 00000000..d64c3eff --- /dev/null +++ b/tests/qbytearray.py @@ -0,0 +1,7 @@ +import typing +from PyQt5 import QtCore + +some_bytearray = QtCore.QByteArray(3, 'a') +some_bytes = bytes(some_bytearray) # type: bytes + +