[PATCH] merge3 fails with python2.3

Martin Pool mbp at sourcefrog.net
Wed Jul 6 01:58:18 BST 2005


On  5 Jul 2005, John A Meinel <john at arbash-meinel.com> wrote:

> I found the bug. It turns out that the way iterables work with python2.3
> is different than with python2.4
> It seems that doing:
> 
> aiter = iter(SequenceMatcher(None, self.base, self.a).get_matching_blocks())
> 
> In python2.4 these evaluate to False when they run out of entries, so:
> 
> while aiter:
>    aiter.next()
> 
> Will loop properly. But in python2.3, they do not evaluate to False,
> instead raising a StopIteration exception. So it basically becomes:
> 
> while True:
>    aiter.next() # This raises a StopIteration exception, which won't be
> caught by the while

It needs to also guard the .next() that gets the first value. 

Rather than have a big try block I think i'll just change them to
regular C-like indexed loops.  (Catching an exception that could come
from anywhere inside makes me uncomfortable.)

> Is there a reason to do "while aiter and biter:"? I assume because you
> only want to call 'next()' on one of them, not both like 'zip()' would do.

That's right, we want to progress through both until one is finished,
but only one of them steps forward on each loop.  Maybe there's a
better way?

I'm not sure if the extensive use of generators in here is really
sensible.  They are a very nice way to separate out code that might be
entwined in other languages.  I wonder how much they cost compared to
building a list?  I suppose a bit more.

-- 
Martin




More information about the bazaar mailing list