PyQt 5.15.1: Signals are unhashable

Florian Bruhin me at the-compiler.org
Sun Sep 13 13:00:14 BST 2020


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20200913/b324dda3/attachment.sig>


More information about the PyQt mailing list