[ZODB-Dev] Storage iterators and IndexError

Jim Fulton jim at zope.com
Mon May 17 15:19:05 EDT 2010


On Sat, May 15, 2010 at 6:52 AM, Hanno Schlichting <hanno at hannosch.eu> wrote:
> On Fri, May 14, 2010 at 8:43 PM, Jim Fulton <jim at zope.com> wrote:
>> There's a test for storage iterators that verifies that they raise
>> a special exception that extends StopIteration and IndexError.
>> This makes storage iterators a bit harder to implement than
>> necessary.
>>
>> Does anyone know of a reason why we should have to raise
>> a special error that raises IndexErrors?
>
> Not really. It sounds like it's trying to do both new-style iterators
> (via __iter__ / next / StopIteration) and old-style iteration (via
> __getitem__ / IndexError) at once.
>
> From http://docs.python.org/reference/datamodel.html about
> "object.__getitem__(self, key)": Note for loops expect that an
> IndexError will be raised for illegal indexes to allow proper
> detection of the end of the sequence.

I new what it was doing. I just didn't know why. :)

Jim

-- 
Jim Fulton


More information about the ZODB-Dev mailing list