def test_compute_hash(): from rpython.rlib.objectmodel import _hash_string, _hash_float, _hash_tuple assert compute_hash("Hello") == _hash_string("Hello") assert compute_hash(7) == 7 assert compute_hash(-3.5) == _hash_float(-3.5) assert compute_hash(None) == 0 assert compute_hash(("world", None, 7)) == _hash_tuple(("world", None, 7)) # class Foo(object): def __hash__(self): return 42 foo = Foo() h = compute_hash(foo) assert h == object.__hash__(foo) assert h == getattr(foo, '__precomputed_identity_hash') assert compute_hash(None) == 0