microsoft/debugpy

Cannot expand attributes of int subclass in Variables, Watch or Debug Console

laundmo opened this issue · 1 comments

Problem

Subclasses of int (and other "primitives") cannot be expanded and their attributes cannot be inspected.

Reproduction

Debug this python file:

class SomeIntSubclass(int):
    def some_method(self):
        pass


class SomeClass:
    def some_method(self):
        pass


normal_instance = SomeClass()
int_instance = SomeIntSubclass(1)
breakpoint()

As you can see, there's no toggle to expand/collapse the attributes list
Image
Image

Solutions

I've orderd solutions i can think of in order of preference

  • Instead of using isinstance(x, int) or a equivalent to check whether a variable is a primitive type, use type(x) is int so only subclasses show up as normal instances.
  • A setting to treat all values, be they "primitives" or not, as objects which can be inspected
  • A special cased command, function, or similar in the Debug Console to inspect a "primitive" as if it was a normal instance

Thanks for the suggestion. I believe this would need some sort of setting

Internally debugpy just does a __repr__ on most variables. That code is here:

.

Transferring to a discussion item for upvotes.