def test_hash(self):
hash(None)
self.assertEqual(hash(1), hash(1L))
self.assertEqual(hash(1), hash(1.0))
hash('spam')
if have_unicode:
self.assertEqual(hash('spam'), hash(unicode('spam')))
hash((0,1,2,3))
def f(): pass
self.assertRaises(TypeError, hash, [])
self.assertRaises(TypeError, hash, {})
# Bug 1536021: Allow hash to return long objects
class X:
def __hash__(self):
return 2**100
self.assertEqual(type(hash(X())), int)
class Y(object):
def __hash__(self):
return 2**100
self.assertEqual(type(hash(Y())), int)
class Z(long):
def __hash__(self):
return self
self.assertEqual(hash(Z(42)), hash(42L))
评论列表
文章目录