Re: [Python-3000] __hash__ : Problem with either documentation or understanding

2008-07-31 Thread Jim Jewett
On 7/29/08, Chris Rebert <[EMAIL PROTECTED]> wrote: > If the latter, than you shouldn't implement __hash__ because, as the > docs you quote say, Bad Things (tm) will happen if someone puts your > object into a dict and then mutates it. Not quite. > So really it comes down to answering the que

Re: [Python-3000] __hash__ : Problem with either documentation or understanding

2008-07-31 Thread Nick Coghlan
Greg Ewing wrote: Nick Coghlan wrote: Objects which compare equal must also end up in the same hash bucket in order for dictionaries to work correctly. And, if its equality with another object can change during its lifetime, it will never work properly in a dictionary. So in that case you sho

Re: [Python-3000] __hash__ : Problem with either documentation or understanding

2008-07-29 Thread Greg Ewing
Nick Coghlan wrote: Objects which compare equal must also end up in the same hash bucket in order for dictionaries to work correctly. And, if its equality with another object can change during its lifetime, it will never work properly in a dictionary. So in that case you should leave __hash__

Re: [Python-3000] __hash__ : Problem with either documentation or understanding

2008-07-29 Thread Nick Coghlan
Charles Hixson wrote: .../Python-3.0b2/Python-3.0b2/Doc/build/html/reference/datamodel.html#object.__hash__ """If a class defines mutable objects and implements a __cmp__() or __eq__() method, it should not implement __hash__(), since the dictionary implementation requires that a key’s hash va

Re: [Python-3000] __hash__ : Problem with either documentation or understanding

2008-07-29 Thread Chris Rebert
Your question isn't really Python-3000-specific, and belongs more on the comp.lang.python list. That said, whether it's right for your object really depends on how you're defining equality for it. Are you defining equality as merely identity (i.e. are they pointers to the same spot in memory) or d