Skip to content

Support nested objects/recursion in mo.inspect #11071

Description

@daniilS

Description

mo.inspect is one of my favourite underrated marimo features. However, quite often I'm dealing with lists of objects, for which inspect just prints the default representation for each child. It'd be great to be able to expand nested objects to view their details in the same way.

Simple example code:

class Point:
    def __init__(self, x: float, y: float):
        self.x = x
        self.y = y


class Line:
    def __init__(self, p1: Point, p2: Point):
        self.p1 = p1
        self.p2 = p2

    @property
    def length(self) -> float:
        return ((self.p2.x - self.p1.x) ** 2 + (self.p2.y - self.p1.y) ** 2) ** 0.5


lines = [Line(Point(0, 0), Point(i, i)) for i in range(5)]

mo.inspect(lines)

Current marimo output:

Image

For reference, I am thinking of something similar to the console.log implementation of most browsers, e.g. Chrome:

Image

Firefox:

Image

Are you willing to submit a PR? (You must receive approval from the team before submitting a PR.)

  • Yes

Alternatives

No response

Additional context

No response

Activity

  1. added theissue type on Oct 2, 2026
  2. kirangadhave commented on Oct 2, 2026

    @kirangadhave
    Member

    Thanks for the report @daniilS

    When mo.inspect renders a list, each element goes through the marimo's normal formatting.

    The Point and Line calss have no __repr__, so each element falls back to default Python object representation <Line object at 0x...>

    You can either implement __repr__ on those classes, see docs (and example) or make them dataclasses like below.

    from dataclasses import dataclass
    
    
    @dataclass
    class Point:
        x: float
        y: float
    
    
    @dataclass
    class Line:
        p1: Point
        p2: Point
    
        @property
        def length(self) -> float:
            return ((self.p2.x - self.p1.x) ** 2 + (self.p2.y - self.p1.y) ** 2) ** 0.5
    
    
    lines = [Line(Point(0, 0), Point(i, i)) for i in range(5)]
    mo.inspect(lines)

    Output:
    Image

  3. daniilS commented on Oct 3, 2026

    @daniilS
    Author

    @kirangadhave yes, but mo.inspect is specifically meant for objects that lack a rich representation, hence my feature request to make it apply recursively to object attributes that also lack a built-in __repr__. In my example, Line and Point are a stand-in for e.g. objects from a third-party library where I have no control over the __repr__. That's exactly why mo.inspect(Point(0, 0)) is useful, because it allows debugging without needing to modify the representation of an existing object.

  4. kirangadhave commented on Oct 5, 2026

    @kirangadhave
    Member

    I agree, but adding support for nested data structure require handling circular references correctly. It's something we would like to do, so I will track the work as todo, but I don't have a timeline on when we will prioritize it.

    Meanwhile for 3rd party libs, you could do something like this to add __repr__ support.

    Warning

    I know this is hacky and this will replace an existing __repr__ if the class has one. But it might be okay for temporary debugging purposes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions