<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&#39;s wanted or not). However, it seems to be fixed in Python 3.0. So this documentation is only &quot;wrong&quot; 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 &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>
&gt;&gt;&gt; class X(object):<br>...&nbsp;&nbsp;&nbsp;&nbsp; def __eq__(self, other):<br>...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return True<br>... <br>&gt;&gt;&gt; x = X()<br>&gt;&gt;&gt; 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 &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information.<br>
&gt;&gt;&gt; class X(object):<br>...&nbsp;&nbsp;&nbsp;&nbsp; def __eq__(self, other):<br>...&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return True<br>... <br>&gt;&gt;&gt; x = X()<br>&gt;&gt;&gt; hash(x)<br>Traceback (most recent call last):<br>&nbsp; File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt;<br>

TypeError: unhashable type: &#39;X&#39;<br><br>Matt<br></div>