[ZODB-Dev] Help! BTrees and hashing on Persistent objects not working
JohnD.Heintz
JohnD.Heintz
Wed, 15 Aug 2001 18:07:08 -0500
The following code raises an AssertionError because the BTree doesn't use=
the=20
Python defined __hash__ methods.
Should I log this as a Collector bug or am I doing something wrong?
John
import ZODB
from BTrees.OOBTree import OOBTree
from ZODB import Persistence
class HashablePersistent(Persistence.Persistent):
"""
"""
def __init__(self):
self.__version =3D "1.0"
self.hashCalled =3D 0
def __hash__(self):
"""
Trivial __hash__ implementation to get identity
"""
self.hashCalled =3D 1
return 5
def __cmp__(self, other):
return 0 # I know this needs to be implemented
p =3D HashablePersistent()
dict =3D {}
dict[p] =3D p
assert p.hashCalled
p =3D HashablePersistent()
btree =3D OOBTree()
btree[p] =3D p
assert p.hashCalled # !!This fails!!
--=20
=2E . . . . . . . . . . . . . . . . . . . . . . .
John D. Heintz | Senior Engineer
1016 La Posada Dr. | Suite 240 | Austin TX 78752
T 512.633.1198 | jheintz@isogen.com
w w w . d a t a c h a n n e l . c o m