[Python-Dev] yeah! for Jeremy and Greg

Barry A. Warsaw bwarsaw@cnri.reston.va.us
Tue, 28 Mar 2000 20:02:16 -0500 (EST)


Changing the definition of class Nums to

class Nums:
    def __getitem__(self, i):
        if 0 <= i < 10: return i
        raise IndexError
    def __len__(self):
        return 10

I.e. adding the __len__() method avoids the SystemError.

Either the *arg call should not depend on the sequence being
lenght-able, or it should error check that the length calculation
doesn't return -1 or raise an exception.

Looking at PySequence_Length() though, it seems that m->sq_length(s)
can return -1 without setting a type_error.  So the fix is either to
include a check for return -1 in PySequence_Length() when calling
sq_length, or instance_length() should set a TypeError when it has no
__len__() method and returns -1.

I gotta run so I can't follow this through -- I'm sure I'll see the
right solution from someone in tomorrow mornings email :)

-Barry