Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] wrong string representation of MagicsDisplay is used in ipython extension #3317

Open
2 tasks done
iloveitaly opened this issue Mar 30, 2024 · 2 comments
Open
2 tasks done

Comments

@iloveitaly
Copy link

Describe the bug

When rich is installed as an ipython plugin output %lsmagic fails to output anything meaningful:

In [21]: %lsmagic
Out[21]: <IPython.core.magics.basic.MagicsDisplay object at 0x10d0a39e0>

This is because __repr__ instead of __str__ is being used on the MagicsDisplay object. The MagicsDisplay have a special method _repr_pretty_. If you update MagicsDisplay and include:

    def __repr__(self):
        return self._lsmagic()

All is well.

Should rich look for _repr_pretty_ and use instead of __str__ or should ipython update MagicsDisplay?

Platform

Click to expand ``` ╭───────────────────────── ─────────────────────────╮ │ A high level console interface. │ │ │ │ ╭──────────────────────────────────────────────────────────────────────────────╮ │ │ │ │ │ │ ╰──────────────────────────────────────────────────────────────────────────────╯ │ │ │ │ color_system = 'truecolor' │ │ encoding = 'utf-8' │ │ file = <_io.TextIOWrapper name='' mode='w' encoding='utf-8'> │ │ height = 53 │ │ is_alt_screen = False │ │ is_dumb_terminal = False │ │ is_interactive = True │ │ is_jupyter = False │ │ is_terminal = True │ │ legacy_windows = False │ │ no_color = False │ │ options = ConsoleOptions( │ │ size=ConsoleDimensions(width=140, height=53), │ │ legacy_windows=False, │ │ min_width=1, │ │ max_width=140, │ │ is_terminal=True, │ │ encoding='utf-8', │ │ max_height=53, │ │ justify=None, │ │ overflow=None, │ │ no_wrap=False, │ │ highlight=None, │ │ markup=None, │ │ height=None │ │ ) │ │ quiet = False │ │ record = False │ │ safe_box = True │ │ size = ConsoleDimensions(width=140, height=53) │ │ soft_wrap = False │ │ stderr = False │ │ style = None │ │ tab_size = 8 │ │ width = 140 │ ╰──────────────────────────────────────────────────────────────────────────────────╯ ╭─── ────╮ │ Windows features available. │ │ │ │ ╭───────────────────────────────────────────────────╮ │ │ │ WindowsConsoleFeatures(vt=False, truecolor=False) │ │ │ ╰───────────────────────────────────────────────────╯ │ │ │ │ truecolor = False │ │ vt = False │ ╰───────────────────────────────────────────────────────╯ ╭────── Environment Variables ───────╮ │ { │ │ 'TERM': 'xterm-256color', │ │ 'COLORTERM': 'truecolor', │ │ 'CLICOLOR': 'true', │ │ 'NO_COLOR': None, │ │ 'TERM_PROGRAM': 'tmux', │ │ 'COLUMNS': None, │ │ 'LINES': None, │ │ 'JUPYTER_COLUMNS': None, │ │ 'JUPYTER_LINES': None, │ │ 'JPY_PARENT_PID': None, │ │ 'VSCODE_VERBOSE_LOGGING': None │ │ } │ ╰────────────────────────────────────╯ platform="Darwin" rich==13.7.1 ```
Copy link

Thank you for your issue. Give us a little time to review it.

PS. You might want to check the FAQ if you haven't done so already.

This is an automated reply, generated by FAQtory

Carreau added a commit to ipython/ipython that referenced this issue Mar 31, 2024
Here's more details on the `rich` side:

Textualize/rich#3317

I don't see a good reason not to overload `__repr__` in this use case
@matkoniecz
Copy link

Seems fixed on ipython/ipython#14378 side, given that there is standard interface for this there should be no need for rich to implement support for custom interface of various projects, right?

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

No branches or pull requests

2 participants