Changing Hash Values Across Versions

Scott David Daniels Scott.Daniels at Acm.Org
Thu Jun 11 20:32:24 CEST 2009

Phil Thompson wrote:
> How stable should the implementation of, for example, a string's hash
> across different Python versions?
> Is it defined that hash("foo") will return the same value for Python 2.5.1,
> 2.6.1 and 2.6.2?
> Thanks,
> Phil
Pretty certain that A.B.* will always hash the same (unacceptable change
as a bugfix), and that there has been no recent need to change the
string hash (it gets a _lot_ of use), so in practice I suspect that
2.3.* through 2.8.* all produce the same string hashes.  However, the
language doesn't guarantee a lot about the value, and I would not be
surprised to see a non-CPython implementation use a different hash.

Generally it is a good idea to keep the result of hash computations
inside the program, and off the persistant store, so I'd want a good
excuse to use the hash "outside."

--Scott David Daniels
Scott.Daniels at Acm.Org

More information about the Python-list mailing list