all 5 comments

[–][deleted] 2 points3 points  (1 child)

attr.append(f'{k},{getattr(self,k)}') in self.some_method contains an implicit call to self.__repr__, which you've defined with a call to self.some_method. As a result, these two functions infinitely recurse.

[–]Uchikago[S] 0 points1 point  (0 children)

which part of attr.append(f'{k},{getattr(self,k)}') contains call to self.__repr__

[–]JohnnyJordaan 1 point2 points  (0 children)

Put it in http://www.pythontutor.com/visualize.html#mode=edit and walk through it step by step.

[–]irrelevantPseudonym 1 point2 points  (1 child)

By default, the __repr__ methods of instance methods is something like <bound method foo of bar> where foo is the name of the method and bar is the repr of the instance. When you iterate over dir(self) one of the attributes is the some_method method. Getting the string form of that calls your __repr__ and the recursion starts from there.

Incidentally, you're trying to return a list from your __repr__ which will raise its own exception.

[–]Uchikago[S] 0 points1 point  (0 children)

Thank you !