PyQt 5.15.1: Signals are unhashable
Phil Thompson
phil at riverbankcomputing.com
Mon Sep 14 18:21:33 BST 2020
On 13/09/2020 13:00, Florian Bruhin wrote:
> Hey,
>
> With PyQt 5.15.1 (which seems to have appeared on PyPI), this example:
>
> from PyQt5.QtCore import QTimer
> t = QTimer()
> d = {}
> d[t.timeout] = None
>
> Fails with:
>
> Traceback (most recent call last):
> File "test.py", line 5, in <module>
> d[t.timeout] = None
> TypeError: unhashable type: 'PyQt5.QtCore.pyqtBoundSignal'
>
> Which breaks pytest-qt's "qtbot.waitSignals" helper (and I'm guessing
> also some other code using PyQt5).
>
> The same kind of thing worked fine with PyQt 5.15.0. I'm guessing this
> is because of "Bound signals can now be tested for equality." -
> probably
> __eq__ was defined, but __hash__ was not. From the Python docs:
>
> A class that overrides __eq__() and does not define __hash__() will
> have its __hash__() implicitly set to None. When the __hash__()
> method of a class is None, instances of the class will raise an
> appropriate TypeError when a program attempts to retrieve their
> hash
> value [...]
>
> https://docs.python.org/3/reference/datamodel.html#object.__hash__
>
> Florian
Fixed in tonight's PyQt5 snapshot.
Thanks,
Phil
More information about the PyQt
mailing list