Message1382
Even if the object defines a __hash__ method, the WeakValueDictionary does not work:
>>> class X(object):
def __init__(self, id):
self.id = id
def __hash__(self):
return hash(self.id)
>>> # Code taken from the CPython example:
>>> import weakref
>>> _id2obj_dict = weakref.WeakValueDictionary()
>>> def remember(obj):
oid = id(obj)
_id2obj_dict[oid] = obj
return oid
>>> x = X(123)
>>> remember(x)
Traceback (innermost last):
...
TypeError: unhashable instance
|
|
Date |
User |
Action |
Args |
2008-02-20 17:17:39 | admin | link | issue1622207 messages |
2008-02-20 17:17:39 | admin | create | |
|