Re: Hashability questions

2012-05-15 Thread Chris Angelico
On Tue, May 15, 2012 at 3:27 PM, Ian Kelly ian.g.ke...@gmail.com wrote: Why?  I can't see any purpose in implementing __eq__ this way, but I don't see how it's broken (assuming that __hash__ is actually implemented somehow and doesn't just raise TypeError).  The requirement is that if two

Re: Hashability questions

2012-05-15 Thread Christian Heimes
Am 15.05.2012 07:27, schrieb Ian Kelly: Why? I can't see any purpose in implementing __eq__ this way, but I don't see how it's broken (assuming that __hash__ is actually implemented somehow and doesn't just raise TypeError). The requirement is that if two objects compare equal, then they

Re: Hashability questions

2012-05-15 Thread Bob Grommes
On Monday, May 14, 2012 8:35:36 PM UTC-5, alex23 wrote: It looks like this has changed between Python 2 and 3: If a class does not define an __eq__() method it should not define a __hash__() operation either; if it defines __eq__() but not __hash__(), its instances will not be usable as

Re: Hashability questions

2012-05-15 Thread Ian Kelly
On Tue, May 15, 2012 at 3:25 AM, Christian Heimes li...@cheimes.de wrote: Code explains more than words. I've created two examples that some issues. Mutable values break dicts as you won't be able to retrieve the same object again: Sure, you'll get no argument from me on that. I was more

Hashability questions

2012-05-14 Thread Bob Grommes
Noob alert: writing my first Python class library. I have a straightforward class called Utility that lives in Utility.py. I'm trying to get a handle on best practices for fleshing out a library. As such, I've done the following for starters: def __str__(self): return str(type(self)) #

Re: Hashability questions

2012-05-14 Thread Chris Kaynor
On Sun, May 13, 2012 at 12:11 PM, Bob Grommes bob.grom...@gmail.com wrote: Noob alert: writing my first Python class library. I have a straightforward class called Utility that lives in Utility.py. I'm trying to get a handle on best practices for fleshing out a library.  As such, I've done

Re: Hashability questions

2012-05-14 Thread Chris Rebert
On Sun, May 13, 2012 at 12:11 PM, Bob Grommes bob.grom...@gmail.com wrote: Noob alert: writing my first Python class library. I have a straightforward class called Utility that lives in Utility.py. I'm trying to get a handle on best practices for fleshing out a library.  As such, I've done

Re: Hashability questions

2012-05-14 Thread Dave Angel
On 05/14/2012 07:38 PM, Chris Kaynor wrote: On Sun, May 13, 2012 at 12:11 PM, Bob Grommes bob.grom...@gmail.com wrote: SNIP The rule is that, if two objects return different results from __hash__, they should never compare equal. The opposite rule also holds true: if two objects compare

Re: Hashability questions

2012-05-14 Thread alex23
On May 14, 5:11 am, Bob Grommes bob.grom...@gmail.com wrote: Obviously there is some sort of default implementation of __hash__() at work and my implementation of _eq_() has somehow broken it. Can anyone explain what's going on? It looks like this has changed between Python 2 and 3: If a

Re: Hashability questions

2012-05-14 Thread Christian Heimes
Am 13.05.2012 21:11, schrieb Bob Grommes: Noob alert: writing my first Python class library. I have a straightforward class called Utility that lives in Utility.py. I'm trying to get a handle on best practices for fleshing out a library. As such, I've done the following for starters:

Re: Hashability questions

2012-05-14 Thread Ian Kelly
On Mon, May 14, 2012 at 7:50 PM, Christian Heimes li...@cheimes.de wrote: Am 13.05.2012 21:11, schrieb Bob Grommes: Noob alert: writing my first Python class library. I have a straightforward class called Utility that lives in Utility.py. I'm trying to get a handle on best practices for