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

Phil Thompson phil at riverbankcomputing.com
Mon Apr 17 12:20:54 BST 2017


On 12 Apr 2017, at 5:16 pm, Gabriel Marcilio <gaheris.sc at gmail.com> wrote:
> 
> 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

As these are really just numbers I've implemented __hash__() for QFlags.

Phil


More information about the PyQt mailing list