[ZODB-Dev] Cannot subclass OOBTree - __delitem__ missing

Tim Peters tim at zope.com
Mon Aug 11 16:06:57 EDT 2003


[Gfeller Martin]
> I'm having continuous problems with B-Trees. I cannot subclass an
> OOBTree, as the __delitem__ method is not defined (despite
> Btrees.Interfaces.IMinimalDictionary.__delitem__() seems to
> indicate that it is available).
>
> >>> from BTrees import OOBTree
> >>> class myBTree(OOBTree.OOBTree):
> ... 	pass
> ...
> >>> bt = myBTree()
> >>> bt['a'] = 1
> >>> del bt['a']
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
> AttributeError: __delitem__
> >>>
>
> This is using Zope 2.6.2b4. If it is indeed a bug, I would
> appreciate if somebody could fix it (I'm not speaking enough C
> for this).

The problem derives from that OOBTree is an ExtensionClass type, which is a
hairy concept implemented in Zope's C code that doesn't always play well
with subclassing from Python (although it goes remarkably far toward being
seamless, it's not perfectly seamless).

In experimental pre-release versions of ZODB (ZODB4 and ZODB 3.3), BTrees
are ordinary "new style" Python classes instead, and subclassing from Python
works fine then.  It won't always work in ZODB versions before those.

> If it is not a bug, please tell me what I should use instead.

I suppose that depends on what you're trying to accomplish <wink>.  In
general, containment ("has a") can usually be used in lieu of inheritance
("is a").




More information about the ZODB-Dev mailing list