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

_ipython_display_ not ignored in the REPL #13667

Open
aulemahal opened this issue May 2, 2022 · 4 comments
Open

_ipython_display_ not ignored in the REPL #13667

aulemahal opened this issue May 2, 2022 · 4 comments

Comments

@aulemahal
Copy link

aulemahal commented May 2, 2022

In the docs, it says, about _ipython_display_, that "This method is ignored in the REPL."
However, when I open a REPL and type the following:

In [1]: class A:
   ...:     def _ipython_display_(self):
   ...:         print('woups')
   ...: 

In [2]: A()

I get:

Out[4]: woups

Thus, it is not doing what the doc says. Is the doc wrong? (I expected something like <__main__.A at 0x7f4ad9bdab20>)

This looks inoffensive here, but my issue came from an object defined in some library that uses the _ipython_display_ method to display a HTML repr, so I only see <IPython.core.display.HTML object>. This object does have a correct __repr__ method implemented, so I expected to see that, as it is the case in the basic python repl.

Thanks!

I tried this with IPython 8.1.1 and 8.3.0, both gave the same result.
I tried with 7.22 and I got what I expected (_ipython_display_ was ignored).

@MrMino MrMino added the bug label May 6, 2022
@MrMino
Copy link
Member

MrMino commented May 6, 2022

I'm going to consider it as a bug, cause it seems to be in the documentation for a reason: 56bafa1. That said, it's not entirely clear to me why wouldn't we want the REPL to use it. @Carreau? @bollwyvl? @takluyver?

@Carreau
Copy link
Member

Carreau commented Jun 9, 2022

Because there is not reason for a shell to not play sounds, or to display images (it just need to be implemented), iTerm2 has it's own protocol and many terminal emulators support sixel.

IPython CLI could perfectly for example display an svg on MacOS by opening quicklook.

For that we need to send all the mimetype and sometime call _ipython_display_.

@MrMino MrMino added documentation and removed bug labels Jun 9, 2022
@MrMino
Copy link
Member

MrMino commented Jun 9, 2022

I'm guessing then, that "This method is ignored in the REPL" part of the documentation is something we should get rid of.

@agoose77
Copy link
Contributor

agoose77 commented Dec 2, 2022

Just ran into this! #13851

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

4 participants