[solved - ItemBase issue] Custom ItemList : RecursionError: maximum recursion depth exceeded while calling a Python object

Problem occurs when implementing a custom ItemBase by inheriting it and it’s due to function __repr__:

__repr__ is defined as:

def __repr__(self): return f'{self.__class__.__name__} {self}'

I assume that {self} again calls __repr__ and it causes the infinite recursion.

As a solution I overwrite __repr__:

def __repr__(self):
     return f'{self.__class__.__name__}{(self.img1.shape, self.img2.shape)}'
     

Which will result in :

ImageTuple(torch.Size([3, 337, 699]), torch.Size([3, 337, 699]))

So maybe this warning should be made to the user, when inheriting from ItemBase, they should re-implement __repr__.

Similarly initializing ItemBase class will result in same error:

ItemBase([1])

I didn’t create a PR for the docs since there might be better solution or something that I am missing.

3 Likes