Comparing None with QByteArray starting with a null byte is inappropriate/inconsistent

Maurizio Berti maurizio.berti at gmail.com
Wed Apr 23 17:20:59 BST 2025


Il giorno mer 23 apr 2025 alle ore 17:57 Phil Thompson <
phil at riverbankcomputing.com> ha scritto:

> The implementation of the conversion from a Python object is different
> in PyQt6 (it just relies on the buffer protocol). I can't remember if
> the QByteArray implementations are different between Qt5 and Qt6.
>

Interesting. I did a quick search and I only found a possibly related
change ( https://codereview.qt-project.org/c/qt/qtbase/+/281289/7 ), but
I'm not sure it's actually the cause of the involuntary "fix". In any case,
it was just curiosity, it's not really important.


> I would never use '==' with None anyway. As None is a singleton I always
> use 'is'.
>

I agree, but I created a default attribute set as "uninitialized", that I'd
later compare with a possibly new value (something like "if self.someData
== newData: return"). Normally, it's obviously more appopriate to use an
empty QByteArray as default, but in some cases it may be necessary to know
if the attribute has already been initialized, without the need to use
another attribute. Right now, I worked around it by using 0 as default,
instead of None.

Thank you again!

MaurizioB

-- 
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20250423/b282059c/attachment.htm>


More information about the PyQt mailing list