I'm trying to straighten out the new BTree.setdefault() code, on

Turns out this can't work like Python's dict.setdefault() in all cases.
This is why:

>>> d = {}
>>> d.setdefault(666)
>>> d
{666: None}

That is, the default for the optional ``default`` argument is None, so when
the key is missing and no explicit default is given (or an explicit default
of None is given), the corrected code tries to associate None with the key.

That's fine for OO and IO trees, but can't work for II or OI or IF trees:
None isn't a possible value in the latter kinds of trees.

Proposal:  make BTree/Bucket setdefault() a two-argument function (3 if you
count ``self`` too).  In practice, an explicit default is always passed, and
not even in theory could we come up with a sane default-default that works
across all tree types.

For more information about ZODB, see the ZODB Wiki:

ZODB-Dev mailing list  -  ZODB-Dev@zope.org

Reply via email to