<div dir="ltr"><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">This may have been true for old style classes, but as new style classes inherit a default __hash__ from object - mutable objects *will* be usable as dictionary keys (hashed on identity) *unless* they implement a __hash__ method that raises a type error.<br>
</blockquote><div><br>I always thought this was a bug in new-style classes (due to the fact that, as you say, they inherit __hash__ from object whether it's wanted or not). However, it seems to be fixed in Python 3.0. So this documentation is only "wrong" for Python 2.x branch.<br>
<br>See:<br><br></div></div>Python 2.6b3+ (trunk:66055, Aug 29 2008, 07:50:39) <br>[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2<br>Type "help", "copyright", "credits" or "license" for more information.<br>
>>> class X(object):<br>... def __eq__(self, other):<br>... return True<br>... <br>>>> x = X()<br>>>> hash(x)<br>-1211564180<br><br>versus<br><br>Python 3.0b3+ (py3k:66055M, Aug 29 2008, 07:52:23) <br>
[GCC 4.2.3 (Ubuntu 4.2.3-2ubuntu7)] on linux2<br>Type "help", "copyright", "credits" or "license" for more information.<br>
>>> class X(object):<br>... def __eq__(self, other):<br>... return True<br>... <br>>>> x = X()<br>>>> hash(x)<br>Traceback (most recent call last):<br> File "<stdin>", line 1, in <module><br>
TypeError: unhashable type: 'X'<br><br>Matt<br></div>