-
Notifications
You must be signed in to change notification settings - Fork 39
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
Raise error when instantiating invalid AnyWidget subclass #45
Conversation
✅ Deploy Preview for anywidget canceled.
|
Thanks for the PR :) I guess another option would be to provide a default for It's technically valid to have a widget without any frontend code I guess (the traitlets stuff will just only run on the python side without any listeners). class MyWidget(anywidget.AnyWidget):
value = traitlets.Int().tag(sync=True)
import ipywidgets
widget = MyWidget()
slider = ipywidgets.IntSlider()
ipywidgets.link((slider, "value"), (widget, "value"))
slider # slider will update widget.value, never need to render widget technically The |
Yeah I think a default no op would be good too. Can close this if you want! |
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.
Looks great! Just some minor comments. I think we should add a unit test.
Co-authored-by: Trevor Manz <[email protected]>
Co-authored-by: Trevor Manz <[email protected]>
in exploring the mechanics of this library, I was breaking all the rules 😂 and created an AnyWidget subclass without
_esm
or_modules
. In which case you see the following javascript error:Obviously: one should just "rtfd" here, but this PR provides a more explicit runtime error.
Since
_esm
is effectively an abstract class attribute, another option here (as opposed to raising in the__init__
), would be to use__init_subclass__
:the main difference there is that the immediate subclass of
AnyWidget
must have_esm
... which could possibly restrict users making their own base classes. So this PR only errors at instantiation