[Python-Dev] RE: [Python-checkins] python/dist/src/Lib weakref.py,1.19,1.20 (original) (raw)
Raymond Hettinger python@rcn.com
Sun, 25 May 2003 03:08:33 -0400
- Previous message: [Python-Dev] RE: [Python-checkins] python/dist/src/Lib weakref.py,1.19,1.20
- Next message: [Python-Dev] RE: [Python-checkins] python/dist/src/Lib weakref.py,1.19,1.20
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 "", 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
- Previous message: [Python-Dev] RE: [Python-checkins] python/dist/src/Lib weakref.py,1.19,1.20
- Next message: [Python-Dev] RE: [Python-checkins] python/dist/src/Lib weakref.py,1.19,1.20
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]