◐ Shell
clean mode source ↗

Message 69773 - Python tracker

Attached find a unified diff that upgrades the bisect module in two 
important ways:

1. bisect and friends now understand cmp, key, and reverse, the same way 
that list.sort does.

2. bisect and insort now have parameterized handedness: instead of using 
two different functions depending on whether you want new items to show 
up before or after existing ones, bisect and insort now take a flag 
called 'right' which can change the handedness on the fly.

Currently this code fails two existing regression tests: 
test_backcompatibility, because bisect is no longer the same as 
bisect_right; and test_non_sequence, because insort now raises 
AttributeError instead of TypeError when called on an int.

Still to do, in order of priority as perceived by me:

1. A C version of the code needs to be written.

2. The error handling should be worked over by somebody with more 
knowledge than I - the regression tests assume that particular failures 
(len-only, get-only, and non-sequence) will happen with one of TypeError 
or AttributeError when in reality they may raise the other.

3. The tests for new functionality should be made more exhaustive.

4. The in-module documentation probably needs cleaning; the rst 
documentation needs my name added to it (a good deal of the existing 
writing is still Fred L Drake's, so I won't replace) and needs to have 
the "section 3.6.4" part linked to Mutable Sequence Types; I couldn't 
find an actual example of that linkage.

5. The godawful conditions in bisect should probably get cleaned up.