mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Issue 2235: __hash__ is once again inherited by default, but inheritance can be blocked explicitly so that collections.Hashable remains meaningful
This commit is contained in:
parent
9ace15ca25
commit
53663a695e
14 changed files with 134 additions and 134 deletions
|
|
@ -3283,12 +3283,20 @@ order (MRO) for bases """
|
|||
self.assertEqual(hash(d), 144)
|
||||
D.__hash__ = lambda self: 100
|
||||
self.assertEqual(hash(d), 100)
|
||||
D.__hash__ = None
|
||||
self.assertRaises(TypeError, hash, d)
|
||||
del D.__hash__
|
||||
self.assertEqual(hash(d), 144)
|
||||
B.__hash__ = None
|
||||
self.assertRaises(TypeError, hash, d)
|
||||
del B.__hash__
|
||||
self.assertEqual(hash(d), 314)
|
||||
C.__hash__ = None
|
||||
self.assertRaises(TypeError, hash, d)
|
||||
del C.__hash__
|
||||
self.assertEqual(hash(d), 42)
|
||||
A.__hash__ = None
|
||||
self.assertRaises(TypeError, hash, d)
|
||||
del A.__hash__
|
||||
self.assertEqual(hash(d), orig_hash)
|
||||
d.foo = 42
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue