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

Add formatter for objects with a __html__ method. #12774

Open
aarondewindt opened this issue Jan 17, 2021 · 1 comment
Open

Add formatter for objects with a __html__ method. #12774

aarondewindt opened this issue Jan 17, 2021 · 1 comment

Comments

@aarondewindt
Copy link

In the spirit of PR #3250, which allows other projects to render IPython HTML objects, I would like to render objects from other projects implementing the __html__ method in IPython.

Can I give it a try? Or is there a reason to not support this?

If it's fine, are there any tips? Do I just need to "copy/paste", adjust and register the _repr_html_ formatter class in https://github.com/ipython/ipython/blob/master/IPython/core/formatters.py? If so I can send out a PR later.

@MrMino
Copy link
Member

MrMino commented Apr 14, 2021

Seems to me that having formatters for __*__ methods is an uncharted territory here. Having an interpretation for popular dunders which do not have an agreed upon semantics (mostly: return value / signature) seems risky.

Feels like there could be an implementation of an object that does not follow IPython's semantics with respect to such method - such object would become unusable in IPython. It's not hard for me to imagine GH issues being thrown around just to make other projects compliant with this one, and that's not a scenario that invites kindness.

Is there anything stopping you from doing obj._repr_html_ = obj.__html__, or is this just about the convenience factor of having it out of the box?

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

No branches or pull requests

2 participants