-
Notifications
You must be signed in to change notification settings - Fork 949
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
Conversation
9ee0852
to
b7aac7f
Compare
Resetting to major release milestone until we figure out the display callback issue noted above. |
@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:
Both situations seem very unlikely. I would be 👍 for merging this in the 7.x series. |
I thought that was one of the primary uses of the display callbacks. |
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. |
ipywidgets/widgets/widget.py
Outdated
that _repr_mimebundle_ is used directly. | ||
""" | ||
if ipython_version_info >= (6, 1): | ||
raise NotImplementedError |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
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. |
Not specifically to create widgets though? Do you have an example? |
I was searching for where Hence my question: where do people use this after all? |
ipywidgets/widgets/widget.py
Outdated
|
||
self._handle_displayed(**kwargs) | ||
def _ipython_display_(self, **kwargs): |
There was a problem hiding this comment.
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)
Hi, any chance this version check can be made for IPython 5.4 and up? The |
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):
... |
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 |
b7aac7f
to
f0f173c
Compare
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. |
this is an artefact of an old version of ipywidgets when this was really used for all nested widgets. |
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) |
f0f173c
to
7dd601b
Compare
Never mind, I rebased instead on master so it is easier and less controversial to review/merge. |
Unrelated failure in the new arm64 test run. I think if it fails a few more times, we should remove the arm64 test runs. |
closed/reopened to kick the tests. I couldn't find a way to restart the tests using the travis ui. |
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.