inherited getitem causes infinite recursion

Viewed 30

I have the following setup and when I try to access the RSet array it gets in a loop.

I cant figure why ?

class Blah:

    def __init__(self, shape,........):
       #!!! it seems here is the culprit
        if isinstance(shape, tuple):
           self.ary = torch.zeros(shape, dtype=dtype)
        else:
           self.ary = shape

    def __getitem__(self,*args):
        print(*args)
        return self.ary.__getitem__(*args)

    def rset(self):
        ..
        return BlahResulSet(ixs,self.ary[ixs,:]) <--

    #def __repr__(self):
    #    return self.ary.__repr__()


class BlahResulSet(Blah):

    def __init__(self, ix_map, *args, **kwargs):
        super().__init__(self, *args, **kwargs)
        self.ix_map = ix_map

    #def __getitem__(self,*args):
    #   print(*args)
    #   return super().__getitem__(*args)



blah = Blah(....)
rs = blah.rset()

rs.ary[0,:]   <----

 RecursionError: maximum recursion depth exceeded

old err:

RecursionError: maximum recursion depth exceeded while getting the repr of an object
0 Answers
Related