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

Use _repr_mimebundle_ and require IPython 6.1 or later. #2021

Merged
merged 3 commits into from
Jan 6, 2020

Conversation

jasongrout
Copy link
Member

@jasongrout jasongrout commented Mar 27, 2018

Fixes #1811

This has the problem (noted in the code) that the display callback now happens before the display message is sent. Before this, the display callback happened after the display message was sent.

CC @SylvainCorlay - what do you think about this? I'm thinking that this backwards compatibility difference would make this actually an 8.0 change, and may cause other problems.

@jasongrout jasongrout added this to the 7.2 milestone Mar 27, 2018
@jasongrout jasongrout force-pushed the mimebundle branch 4 times, most recently from 9ee0852 to b7aac7f Compare March 28, 2018 06:14
@jasongrout jasongrout modified the milestones: 7.2, Major release Mar 28, 2018
@jasongrout
Copy link
Member Author

Resetting to major release milestone until we figure out the display callback issue noted above.

@SylvainCorlay
Copy link
Member

@jasongrout I think that it is very unlikely that this order has any consequences.

I can see two cases where this would be an issue:

  • when someone overrides Jupyter's display hook to do more than sending the message, and they also rely on the display callbacks, and expect them to be called synchronously after the display hook is called.
  • in cases where the display callbacks would send other messages to the frontend (such as instantiating other widgets) and rely on the front end processing messages in order.

Both situations seem very unlikely. I would be 👍 for merging this in the 7.x series.

@jasongrout
Copy link
Member Author

jasongrout commented Nov 19, 2018

in cases where the display callbacks would send other messages to the frontend (such as instantiating other widgets) and rely on the front end processing messages in order.

I thought that was one of the primary uses of the display callbacks.

@jasongrout
Copy link
Member Author

I think a relevant question is: what are the on_displayed python-side hooks being used for? Does it make sense to get rid of the concept altogether? It's a bit of a weird concept when you have possibly multiple views of a widget.

CC also @maartenbreddels, who wanted the view count attribute, which is somewhat related.

that _repr_mimebundle_ is used directly.
"""
if ipython_version_info >= (6, 1):
raise NotImplementedError
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this should be raise NotImplemented?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, NotImplemented is not an error class, so raising that will throw a TypeError.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(compare methods return NotImplemented, while subclasses with undefined methods raise NotImplementedError: https://docs.python.org/3.6/library/exceptions.html#NotImplementedError, https://docs.python.org/3.6/library/constants.html#NotImplemented)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, but the docstring lies then. I cannot find which should be the right behaviour actually (return NotImplemented, or raise the error).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or do what @SylvainCorlay said and just put the definition into an if statement.

@maartenbreddels
Copy link
Member

I doubt the order matters, although you can add it to the ioloop to be executed later. But indeed, _view_count is more useful.

It does make it easier to use, and in order not to break too much, I'd say, let us break the order changing, but keep the event.

@SylvainCorlay
Copy link
Member

in cases where the display callbacks would send other messages to the frontend (such as instantiating other widgets) and rely on the front end processing messages in order.

I thought that was one of the primary uses of the display callbacks.

Not specifically to create widgets though? Do you have an example?

@jasongrout
Copy link
Member Author

Not specifically to create widgets though? Do you have an example?

I was searching for where on_displayed is used, and I couldn't find very many examples anywhere I looked on GitHub. It's used once in interact to run the function initially, for example.

Hence my question: where do people use this after all?


self._handle_displayed(**kwargs)
def _ipython_display_(self, **kwargs):
Copy link
Member

@SylvainCorlay SylvainCorlay Nov 20, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jasongrout the definition of _ipython_display_ could be behind a if statement.

    if ipython_version_info < (6,  1):
        def _ipython_display_(self, **kwargs):
            """Called when `IPython.display.display` is called on a widget.
            Note: only defined for IPython <6.1.
            """
            data = self._repr_mimebundle_(**kwargs)
            if data:
                display(data, raw=True)

@Madhu94
Copy link
Contributor

Madhu94 commented Jan 5, 2019

Hi, any chance this version check can be made for IPython 5.4 and up? The _repr_mimebundle definition was backported to 5.x branch - ipython/ipython#10544

@flying-sheep
Copy link
Contributor

flying-sheep commented Mar 4, 2019

that means the check would be the following?

if (5, 4) < ipython_version_info or (6, 0) <= ipython_version_info < (6, 1):
    def _ipython_display_(self, **kwargs):
         ...

@jasongrout
Copy link
Member Author

jasongrout commented Mar 4, 2019

Perhaps we just make a new major release of ipywidgets that cleans this up and updates our dependency on ipython. IPython 6.1 was released in May 2017 - it's been nearly two years, so I think it's okay to update the dependency.

Edit: this could also go along with dropping python 2 support in the next major release

@jasongrout
Copy link
Member Author

Now this is rebased on #2654. Again, I looked in a number of packages, and no one seemed to be using the on_displayed python callback (either for something they needed, or even correctly propagating it to children), so I just removed it. ipyleaflet seemed to be the only one to propagate it to children, but no children were using it to do anything.

@jasongrout jasongrout modified the milestones: Major release, 8.0 Dec 31, 2019
@jasongrout jasongrout changed the title Use _repr_mimebundle_ in IPython 6.1 or later. Use _repr_mimebundle_ and require IPython 6.1 or later. Dec 31, 2019
@SylvainCorlay
Copy link
Member

ipyleaflet seemed to be the only one to propagate it to children, but no children were using it to do anything.

this is an artefact of an old version of ipywidgets when this was really used for all nested widgets.

@SylvainCorlay
Copy link
Member

There seems to be commits unrelated to this in the PR (update to lumino etc).

@jasongrout
Copy link
Member Author

There seems to be commits unrelated to this in the PR (update to lumino etc).

It is rebased on #2654, so it includes those commits (that should be merged first)

@jasongrout
Copy link
Member Author

Never mind, I rebased instead on master so it is easier and less controversial to review/merge.

@jasongrout
Copy link
Member Author

Unrelated failure in the new arm64 test run. I think if it fails a few more times, we should remove the arm64 test runs.

@jasongrout jasongrout closed this Dec 31, 2019
@jasongrout jasongrout reopened this Dec 31, 2019
@jasongrout
Copy link
Member Author

closed/reopened to kick the tests. I couldn't find a way to restart the tests using the travis ui.

@SylvainCorlay SylvainCorlay merged commit a1c940a into jupyter-widgets:master Jan 6, 2020
@mgeier mgeier mentioned this pull request Jan 8, 2020
@lock lock bot added the resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion. label May 21, 2020
@lock lock bot locked as resolved and limited conversation to collaborators May 21, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
resolved-locked Closed issues are locked after 30 days inactivity. Please open a new issue for related discussion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

output widget append_display_data does not display widgets
5 participants