PyQt 5.15.1: Signals are unhashable
Florian Bruhin
me at the-compiler.org
Wed Sep 16 14:49:52 BST 2020
On Mon, Sep 14, 2020 at 06:21:33PM +0100, Phil Thompson wrote:
>
> 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.
Thank you!
FWIW when using pytest-qt's "with waitSignals([sig1, sig2], order='strict'):",
this can be worked around via "with waitSignal(sig1), waitSignal(sig2):"
instead (as long as the returned "blocker" value isn't needed):
https://github.com/qutebrowser/qutebrowser/commit/b55675ad4afe12be7e4a4f39960bb58818c502f8
Florian
--
me at the-compiler.org (Mail/XMPP) | https://www.qutebrowser.org
https://bruhin.software/ | https://github.com/sponsors/The-Compiler/
GPG: 916E B0C8 FD55 A072 | https://the-compiler.org/pubkey.asc
I love long mails! | https://email.is-not-s.ms/
-------------- 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/20200916/fa2cb447/attachment.sig>
More information about the PyQt
mailing list