summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-06-28 09:54:58 (GMT)
committerGitHub <noreply@github.com>2022-06-28 09:54:58 (GMT)
commitefdc9d68de84410b468c2dc87b371b4c3d0663ac (patch)
tree6b2e816555b591cdbc21070fb75283d26b40d25f /Lib
parent71d5299b73c854a7b0e12eb5d0a524579723660b (diff)
downloadcpython-efdc9d68de84410b468c2dc87b371b4c3d0663ac.zip
cpython-efdc9d68de84410b468c2dc87b371b4c3d0663ac.tar.gz
cpython-efdc9d68de84410b468c2dc87b371b4c3d0663ac.tar.bz2
gh-87995: Make MappingProxyType hashable (GH-94252)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_types.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/test/test_types.py b/Lib/test/test_types.py
index 8556ca3..f00da0a 100644
--- a/Lib/test/test_types.py
+++ b/Lib/test/test_types.py
@@ -1203,6 +1203,16 @@ class MappingProxyTests(unittest.TestCase):
self.assertDictEqual(mapping, {'a': 0, 'b': 1, 'c': 2})
self.assertDictEqual(other, {'c': 3, 'p': 0})
+ def test_hash(self):
+ class HashableDict(dict):
+ def __hash__(self):
+ return 3844817361
+ view = self.mappingproxy({'a': 1, 'b': 2})
+ self.assertRaises(TypeError, hash, view)
+ mapping = HashableDict({'a': 1, 'b': 2})
+ view = self.mappingproxy(mapping)
+ self.assertEqual(hash(view), hash(mapping))
+
class ClassCreationTests(unittest.TestCase):