[ZCM] [ZC] 1829/ 6 Comment "bug in IISet.minKey(maxKey)"

Collector: Zope Bugs, Features, and Patches ... zope-coders-admin at zope.org
Sun Jul 3 12:25:43 EDT 2005


Issue #1829 Update (Comment) "bug in IISet.minKey(maxKey)"
 Status Resolved, Zope/bug medium
To followup, visit:
  http://www.zope.org/Collectors/Zope/1829

==============================================================
= Comment - Entry #6 by tim_one on Jul 3, 2005 12:25 pm

This issue is closed, so if you have other complaints please open a different issue(s).

BTree method docstrings are like Python's:  they're brief descriptions, meant to jog your memory, and that's all.  Like Python's:

>>> [].__getitem__.__doc__
'x.__getitem__(y) <==> x[y]'

That doesn't say anything about exceptions, and it's just "common sense" that if you ask for an index position that doesn't exist, some exception will get raised.  In Python, you read the reference manuals if you need more detail; in ZODB you read the interface.  For that reason I was happy to change the interface here, but I'm not going to spend time adding "obvious" picky details to docstrings; most people find them annoying.

I agree the text of the message could be clearer, but that's harder to implement than you might think.  The cost/benefit ratio is so high that if you open an issue about that (which is fine), I doubt I could justify spending time on it.  Perhaps someone else could, although most everyone else is afraid to touch the BTree code ;-)
________________________________________
= Comment - Entry #5 by suvit on Jul 3, 2005 5:44 am

and change 'empty tree', 'empty bucket' to
'doesn't exist any key satisfying the conditions'
________________________________________
= Comment - Entry #4 by suvit on Jul 3, 2005 5:38 am

Oh, I think I not completely understand the Interface docstrings, thank you Tim for your explanation.
but what about the method`s docstrings? :)).
________________________________________
= Resolve - Entry #3 by tim_one on Jul 1, 2005 5:45 pm

 Status: Pending => Resolved

The BTree {min,max}Key() interface docstrings were changed to clarify that an exception is raised if no key satisfies the request.  Changed for ZODBs 3.2.9, 3.4.1, and 3.5.
________________________________________
= Comment - Entry #2 by tim_one on Jul 1, 2005 8:33 am

Well, in your examples there doesn't exist any key satisfying the conditions, so it's impossible to return anything (e.g., there is no value >= 15 in range(10)).  An exception is appropriate.  Issue 99 was an actual bug, where an exception was being raised in non-exceptional cases.

The only thing I might do in response to this is change the interface docs to be explicit about that ValueError is raised if you ask for a key that doesn't exist.  It's unusual for an interface to pretend to list all possible exceptions, though.  For example, you might also see TypeError if you pass a key of a silly type, and you might also see MemoryError if there's not enough RAM left to build the result.
________________________________________
= Request - Entry #1 by suvit on Jul 1, 2005 5:35 am

>>> from BTrees.IIBTree import IISet, IITreeSet
>>> iset = IISet(range(10))
>>> iset.minKey(15)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: empty bucket
>>> iset.keys(15)
[]
>>> iset.keys(5,15)
[5, 6, 7, 8, 9]
>>> iset.maxKey(5)
5
>>> iset.maxKey(-5)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: empty bucket
>>> itset = IITreeSet()
>>> itset = IITreeSet(range(10))
>>> itset.minKey(15)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: empty tree
>>> itset.minKey(10)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
ValueError: empty tree
>>> itset.minKey(9)
9
>>> itset.minKey(-5)
0
but based on IKeyed Interface IISet or IITreeSet objects must return the smallest key >= min ( largest key <= max) not ValueError.

this bug is similar to http://www.zope.org/Collectors/Zope/99
==============================================================



More information about the Zope-Collector-Monitor mailing list