Arghh. One more example always arises after going to bed. The original required only equality. The new version requires equality, hashability, *and* weak referencability. Python 2.3b1 (#40, Apr 25 2003, 19:06:24) [MSC v.1200 32 bit (Intel)] on win32 Type "copyright", "credits" or "license" for more information. IDLE 0.8 -- press F1 for help >>> import weakref >>> class One: def __eq__(self, other): return other == 1 def __hash__(self, other): return hash(1) >>> wkd = weakref.WeakKeyDictionary() >>> o = One() >>> wkd[o] = 1 >>> len(wkd) 1 >>> del wkd[1] >>> len(wkd) 0 Python 2.3b1+ (#40, May 23 2003, 00:08:36) [MSC v.1200 32 Type "help", "copyright", "credits" or "license" for more >>> class One: ... def __eq__(self,other): return other==1 ... def __hash__(self): return hash(1) ... >>> import weakref >>> wkd = weakref.WeakKeyDictionary() >>> o = One() >>> wkd[o] = 1 >>> len(wkd) 1 >>> del wkd[1] Traceback (most recent call last): File "<stdin>", line 1, in ? File "C:\PY23\lib\weakref.py", line 167, in __delitem__ del self.data[ref(key)] TypeError: cannot create weak reference to 'int' object >>> len(wkd) 1 Raymond
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4