[PyQt] [Bug report] PyQt5.QtCore.Alignment not hashable

Gabriel Marcilio gaheris.sc at gmail.com
Wed Apr 12 17:16:56 BST 2017


Hello

I am having issues with PyQt5.QtCore.Alignment values. I cannot use then as
dict keys because those values are not hashable.
The issue can be seen in the following snippet:

    # AlignmentFlag Works fine
    alignment_flag = Qt.AlignTop
    assert hasattr(alignment_flag, '__hash__')
    assert hash(alignment_flag) == 32
    assert alignment_flag.__hash__() == 32

    # Alignment is unhashable
    alignment  =  Qt.AlignTop | Qt.AlignLeft
    assert hasattr(alignment, '__hash__')
    assert hash(alignment) != 0 # <- TypeError: unhashable type: 'Alignment'
    assert alignment.__hash__() != 0  # <- TypeError: 'NoneType' object is
not callable

The Alignment class overrides the __eq__ method but does not provide an
implementation for __hash__ method, and this makes the object unhashable.

This code worked with python 2.7 pyqt 5.5.1

I am having issues with python 3.5.2 and pyqt  5.6.0

Thanks in advance

Gabriel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170412/ed5109df/attachment.html>


More information about the PyQt mailing list