Skip to content

Make SomeIPythonRepr traverse the MRO for the type? #36801

@user202729

Description

@user202729

Problem Description

Currently the implementation of SomeIPythonRepr just check the type of the function:

try:
pretty_repr = self._type_repr[type(obj)]
except KeyError:
return False
pretty_repr(obj, p, cycle)
return True

Would it be desirable to traverse the MRO instead?

https://github.com/ipython/ipython/blob/dd7f1e1894395f59649a84f94af8c9710202b08f/IPython/lib/pretty.py#L380-L412

What's the difference? This affects the printing when there's some user class inherit from one of the default IPython-printable classes.

sage: class A(list):
....:     pass
sage: A([1..30])
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
sage: [1..30]
[1,
 2,
 3,
 4,
 5,
 6,
 7,
 8,
 9,
 10,
 11,
 12,
 13,
 14,
 15,
 16,
 17,
 18,
 19,
 20,
 21,
 22,
 23,
 24,
 25,
 26,
 27,
 28,
 29,
 30]

The functionally equivalent code in IPython does break the lines in both cases.

Proposed Solution

Alternatives Considered

Additional Information

No response

Is there an existing issue for this?

  • I have searched the existing issues for a bug report that matches the one I want to file, without success.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions