I found when converting some Python2/Qt4 code to Python3/Qt5, that apparently QStandardItem can no longer be used as a dict key in as it doesn't have __hash__
implemented, and therefore is not considered immutable anymore.
Those two snippets show the issue:
PyQt4:
>>> from PyQt4 import QtGui
>>> a = QtGui.QStandardItem()
>>> b = {}
>>> b[a] = "1"
>>> a.__hash__()
2100390
PyQt5:
>>> from PyQt5 import QtGui
>>> a = QtGui.QStandardItem()
>>> b = {}
>>> b[a] = "1"
TypeError: unhashable type: 'QStandardItem'
>>> a.__hash__()
TypeError: 'NoneType' object is not callable
Why was the change done? Should I not use QStandardItem as a dict key?
The obvious workaround would be to subclass QStandardItem and reimplement a trivial version of __hash__
(which I've done). But is there anything I'm missing?