[ZODB-Dev] [BTrees] (small) XXSet/XXTreeSet inconsistency

Tim Peters tim at zope.com
Fri Nov 7 17:57:02 EST 2003


[Dieter Maurer]
> from BTrees.OOBTree import OOSet, OOTreeSet
>
> [].extend(OOSet())  # ok
> [].extend(OOTreeSet()) # TypeError: list.extend() argument must be
> a sequence

These stem from that you're using an old Python and an old implementation of
BTrees.  Of course "old" may mean "latest released" wrt ZODB <wink>, but all
the same we can't use the new implementation of BTrees so long as Python 2.1
has to be supported.  These will work fine in ZODB 3.3 and Python 2.3,
because all BTree-based data structures in 3.3 implement the newer Python
iteration protocol (and list.extend() accepts any iterable object):

C:\Code\zodb33-devel-branch>\python23\python
Python 2.3.2 (#49, Oct  2 2003, 20:02:00) [MSC v.1200 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from BTrees.OOBTree import *
>>> [].extend(OOSet())
>>> [].extend(OOTreeSet())
>>> x = []
>>> ts = OOTreeSet(range(20))
>>> ts
<BTrees._OOBTree.OOTreeSet object at 0x006EBFA8>
>>> x.extend(ts)
>>> x
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>>> list(ts)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>>> tuple(ts)
(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19)
>>> 12 in ts
True
>>> 20 in ts
False
>>>

The last two illustrate that the BTree-based objects will also support the
newer __contains__ protocol (per-type definition of what the "in" operator
means -- it's implemented to be a synonym of has_key in 3.3).

>>> sum(ts)
190
>>>

That one just illustrates that all sorts of things accept iterable arguments
("sum" is a new builtin in 2.3, BTW).




More information about the ZODB-Dev mailing list