[ZODB-Dev] BTree sets and unhashable objects

Casey Duncan casey at zope.com
Wed Jun 18 14:05:10 EDT 2003


AFAIK objects must compare consistently in order to work with sets. I don't 
think they have to be hashable.

Since Python instances default to comparison by memory address (id), that 
doesn't work too well with putting them in a set that persists across 
different python sessions. So by default, things are comparable, but not 
consistently.

You either need to make the instances compare stably (by assigning them a 
persistent unique id or by some other means), or just store the ids in the 
set in place of the objects themselves. A workaround might be to make your 
instances compare based on oid rather than id. At least that would be stable.

-Casey

On Wednesday 18 June 2003 12:48 pm, Roché Compaan wrote:
> I was using OOSet for set operations on sequences of objects in the ZODB
> and was getting horrably incorrect results. After I reread the Btrees Wiki
> I noticed that the objects should be hashable, which they weren't of
> course. Maybe the set classes can be so nice as to not accept unhashable
> objects in the first place and stop stupidly forging ahead in its tracks
> ;-)
> 
> -- 
> Roché Compaan
> Upfront Systems                 http://www.upfrontsystems.co.za
> 
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
> 
> ZODB-Dev mailing list  -  ZODB-Dev at zope.org
> http://mail.zope.org/mailman/listinfo/zodb-dev
> 




More information about the ZODB-Dev mailing list