Details
Description
bool(QByteArray(b"")) is True, but should be false (like bool(QByteArray())):
>>> from PySide6.QtCore import QByteArray >>> ba1 = QByteArray(b"test") >>> ba2 = QByteArray(b"") >>> ba3 = QByteArray() >>> ba1.__bool__ <method-wrapper '__bool__' of PySide6.QtCore.QByteArray object at 0x7f4544f35800> >>> len(ba1) 4 >>> len(ba2) 0 >>> len(ba3) 0 >>> bool(ba1) True >>> bool(ba2) True # !!! >>> bool(ba3) False
Note especially that:
>>> ba2 == ba3 True
so we have two objects which are equal, yet produce different results with bool().
I believe the fix would be to just not define a __bool__ on it. According to the Python data model: When __bool__ is not defined, __len__() is called, if it is defined, and the object is considered true if its result is nonzero.
I tried to find where this is actually implemented in
sources/pyside6/PySide6/QtCore/typesystem_core_common.xml or sources/pyside6/PySide6/glue/qtcore.cpp but failed to find it.