2

Is there a way to make PyCharm debugger display items of a custom-made sequence-like object?
I would like it to be the default view, without resorting to displaying list(x).

Example custom Sequence object:

class WrappedList(Sequence):
def __init__(self, wrapped_list):
    self.wrapped_list = wrapped_list

def __getitem__(self, i):
    return self.wrapped_list[i]

def __len__(self) -> int:
    return len(self.wrapped_list)

def __repr__(self):
    return f'WrappedList({self.wrapped_list})'

PyCharm displays it like this:

WrappedList

I would like it to be displayed like a collection of elements:

list(WrappedList)

Note: This doesn't seem to be that important in this simple example, but when the object is implemented in C code there is no easy way to get to the contents from a watch window, as there is no embedded wrapped_list field to look at:
CppSequence

Zbyl
  • 2,130
  • 1
  • 17
  • 26
  • 1
    Simple answer is no. I wrote [one extensive answer](https://stackoverflow.com/q/67520639) about the display order of variables in the variables tab of the debugger tool window, and another [short answer](https://stackoverflow.com/a/67645390) about an interesting case where inheritance changes the display completely. I also tried to mention all the alternatives I have found. – bad_coder Jul 13 '21 at 10:57
  • In this case you made the right choice, if you can wrap an object so it displays conveniently that may be worth the effort if you are debugging a particularly labor intensive section of code. – bad_coder Jul 13 '21 at 11:16

0 Answers0