[Twisted-Python] Why must RemoteCacheObservers be hashable?
Daniel Sank
sank.daniel at gmail.com
Wed Nov 27 09:34:24 MST 2013
I just wrote up a class that allows dicts to be be pb.Cacheable.
Everything works hunky-dory but only if I implement __hash__, which is
problematic for mutable objects for reasons explained thoroughly
elsewhere. The problem comes from
twisted.spread.flavors.RemoteCacheObserver:
class RemoteCacheObserver:
...
def __hash__(self):
"""Generate a hash unique to all L{RemoteCacheObserver}s for
this broker/perspective/cached triplet
"""
return ( (hash(self.broker) % 2**10)
+ (hash(self.perspective) % 2**10)
+ (hash(self.cached) % 2**10))
As we can see, self.cached (which is the pb.Cacheable instance) must
be hashable.
Why?
More information about the Twisted-Python
mailing list