[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] QTreeWidgetItem is not hashable in Py3
From:       Phil Thompson <phil () riverbankcomputing ! com>
Date:       2017-03-29 21:22:42
Message-ID: 48D7D8E5-BEEF-402A-92B4-4180659B7481 () riverbankcomputing ! com
[Download RAW message or body]

On 29 Mar 2017, at 10:14 pm, Barry Scott <barry@barrys-emacs.org> wrote:
> 
> 
> > On 29 Mar 2017, at 16:41, Phil Thompson <phil@riverbankcomputing.com> wrote:
> > 
> > On 28 Mar 2017, at 5:31 pm, Sambhav Kothari <sambhavs.email@gmail.com> wrote:
> > > 
> > > Hi,
> > > QTreeWidgetItem seems to be no longer hashable in py3.
> > > 
> > > I am using pyqt5.8.1 and py3.6. Is this a known issue?
> > 
> > Python considers a type to be unhashable if it has a comparison operator (which \
> > QTreeWidgetItem does).
> 
> int and str are hashable and have comparison operator.

I should have added "and doesn't have an explicit __hash__() implementation".

> Phil, I'm reacll I read a release notes of yours about this change.
> 
> I guess the only immutable property that you can hash is the memory address of the \
> object. Its text() property can be changed at any time. No to mention its list of \
> parents. Would that be useful? 
> > Should should be able to implement __hash__() in a sub-class that does what you \
> > want.
> 
> I'd guess that its the text() and parent list that is interesting to hash and not \
> the item itself.

I could have added an explicit implementation of __hash__() that returned id(self) \
(which is what would happen automatically for types without a comparison operator) \
but I prefered to let Python do what it wanted to do. As I suggested you can always \
implement that in your own sub-class.

Phil
_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic