[Zope-dev] difference between OOSet and OOTreeSet?

Gary Poster gary at zope.com
Thu Mar 1 12:43:48 EST 2007


On Mar 1, 2007, at 12:01 PM, Chris Withers wrote:

> Hi Gary,
>
> Gary Poster wrote:
>>> What should I be using?
>> TreeSet.
>
> Interesting, okay, so how should I work around this bogosity?
> Is this a bug?
>
> >>> from BTrees.OOBTree import OOTreeSet,OOSet
> >>> for i in OOSet((1,2,3)): print i,
> ....
> 1 2 3
> >>> for i in OOTreeSet((1,2,3)): print i,
> ....
> 1 2 3
> >>>
> >>> for i in reversed(OOSet((1,2,3))): print i,
> ....
> 3 2 1
> >>> for i in reversed(OOTreeSet((1,2,3))): print i,
> ....
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> TypeError: argument to reversed() must be a sequence

The fact that this works for the OOSet is an implementation accident.

As discussed elsewhere in this thread, sets are not sequences.  The  
fact that the elements are ordered is an implementation detail  
(although given that these sets are essentially the keys of a BTree,  
it's unsurprising that they are).

You could argue that reversed(OOSet((1,2,3))) should raise an  
exception.  IMO, why bother.

Gary


More information about the Zope-Dev mailing list