diff options
| author | Guido van Rossum <guido@python.org> | 2006-08-21 23:36:26 +0000 |
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 2006-08-21 23:36:26 +0000 |
| commit | 389381564cfa936c8e50bc51dc53b55cba857652 (patch) | |
| tree | 7259a38e0d6c06e5519276336ed26a593166de1d /Lib | |
| parent | 5431ee4a499e173c5638297de30a965ed2206c66 (diff) | |
| download | cpython-git-389381564cfa936c8e50bc51dc53b55cba857652.tar.gz | |
Change the way __hash__ is inherited; when __eq__ or __cmp__ is overridden
but __hash__ is not, set __hash__ explicitly to None (and tp_hash to NULL).
All unit tests pass now!
Diffstat (limited to 'Lib')
| -rw-r--r-- | Lib/test/mapping_tests.py | 4 | ||||
| -rw-r--r-- | Lib/test/test_dict.py | 4 |
2 files changed, 8 insertions, 0 deletions
diff --git a/Lib/test/mapping_tests.py b/Lib/test/mapping_tests.py index 1c570b6d34..b917540d49 100644 --- a/Lib/test/mapping_tests.py +++ b/Lib/test/mapping_tests.py @@ -545,6 +545,8 @@ class TestHashMappingProtocol(TestMappingProtocol): class BadEq(object): def __eq__(self, other): raise Exc() + def __hash__(self): + return 24 d = self._empty_mapping() d[BadEq()] = 42 @@ -630,6 +632,8 @@ class TestHashMappingProtocol(TestMappingProtocol): class BadCmp(object): def __eq__(self, other): raise Exc() + def __hash__(self): + return 42 d1 = self._full_mapping({BadCmp(): 1}) d2 = self._full_mapping({1: 1}) diff --git a/Lib/test/test_dict.py b/Lib/test/test_dict.py index f16884607e..7295f41b78 100644 --- a/Lib/test/test_dict.py +++ b/Lib/test/test_dict.py @@ -76,6 +76,8 @@ class DictTest(unittest.TestCase): class BadEq(object): def __eq__(self, other): raise Exc() + def __hash__(self): + return 24 d = {} d[BadEq()] = 42 @@ -375,6 +377,8 @@ class DictTest(unittest.TestCase): class BadCmp(object): def __eq__(self, other): raise Exc() + def __hash__(self): + return 42 d1 = {BadCmp(): 1} d2 = {1: 1} |
