<div class="gmail_quote">On Sun, Jan 15, 2012 at 6:30 AM, Stefan Behnel <span dir="ltr"><<a href="mailto:stefan_ml@behnel.de">stefan_ml@behnel.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Terry Reedy, 14.01.2012 06:43:<br>
<div class="im">> On 1/13/2012 8:58 PM, Gregory P. Smith wrote:<br>
><br>
>> It is perfectly okay to break existing users who had anything depending<br>
>> on ordering of internal hash tables. Their code was already broken.<br>
><br>
> Given that the doc says "Return the hash value of the object", I do not<br>
> think we should be so hard-nosed. The above clearly implies that there is<br>
> such a thing as *the* Python hash value for an object. And indeed, that has<br>
> been true across many versions. If we had written "Return a hash value for<br>
> the object, which can vary from run to run", the case would be different.<br>
<br>
</div>Just a side note, but I don't think hash() is the right place to document<br>
this. </blockquote><div><br>You mean we shouldn't document that the hash() of a string will vary per run?<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
Hashing is a protocol in Python, just like indexing or iteration.<br>
Nothing keeps an object from changing its hash value due to modification,<br>
</blockquote><div><br>Eh? There's a huge body of cultural awareness that only immutable objects should define a hash, implying that the hash remains constant during the object's lifetime.<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
and that would even be valid in the face of the usual dict lookup<br>
invariants if changes are only applied while the object is not referenced<br>
by any dict.</blockquote><div><br>And how would you know it isn't?<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"> So the guarantees do not depend on the function hash() and may<br>
be even weaker than your above statement.<span class="HOEnZb"></span><br></blockquote></div><br>There are no actual guarantees for hash(), but lots of rules for well-behaved hashes.<br clear="all"><br>-- <br>--Guido van Rossum (<a href="http://python.org/~guido">python.org/~guido</a>)<br>