Re: [Python-Dev] [Python-checkins] cpython (3.3): Issue #15814: Use hash function that is compatible with the equality
On Sat, Nov 3, 2012 at 3:07 AM, stefan.krah
+ # equality-hash invariant + x = ndarray(list(range(12)), shape=[12], format='B') + a = memoryview(nd) + + y = ndarray(list(range(12)), shape=[12], format='b') + b = memoryview(nd) + + z = ndarray(list(bytes(chr(x), 'latin-1') for x in range(12)), + shape=[12], format='c') + c = memoryview(nd) + + if (a == b): + self.assertEqual(hash(a), hash(b)) + + if (a == c): + self.assertEqual(hash(a), hash(c)) + + if (b == c): + self.assertEqual(hash(b), hash(c))
These checks could do with a comment explaining why the if statements are needed (I'm assuming something to do with memory order). Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia
Nick Coghlan
+ if (b == c): + self.assertEqual(hash(b), hash(c))
These checks could do with a comment explaining why the if statements are needed (I'm assuming something to do with memory order).
The checks aren't needed; they were supposed to spell out the equality-hash relationship. But that isn't obvious, so I'll add a comment or remove them. Stefan Krah
On Sat, 3 Nov 2012 10:59:23 +0100
Stefan Krah
Nick Coghlan
wrote: + if (b == c): + self.assertEqual(hash(b), hash(c))
These checks could do with a comment explaining why the if statements are needed (I'm assuming something to do with memory order).
The checks aren't needed; they were supposed to spell out the equality-hash relationship.
Better use assertEqual(), then. Regards Antoine.
participants (3)
-
Antoine Pitrou
-
Nick Coghlan
-
Stefan Krah