Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: no need to have Comm as a trait
Browse files Browse the repository at this point in the history
comm is mostly for internal use, and only causes runtime overhead.
maartenbreddels committed Sep 29, 2022
1 parent 07632dd commit c1c34f9
Showing 2 changed files with 4 additions and 13 deletions.
2 changes: 0 additions & 2 deletions ipywidgets/widgets/tests/utils.py
Original file line number Diff line number Diff line change
@@ -26,15 +26,13 @@ def close(self, *args, **kwargs):
undefined = object()

def setup_test_comm():
Widget.comm.klass = DummyComm
ipywidgets.widgets.widget.Comm = DummyComm
_widget_attrs['_ipython_display_'] = Widget._ipython_display_
def raise_not_implemented(*args, **kwargs):
raise NotImplementedError()
Widget._ipython_display_ = raise_not_implemented

def teardown_test_comm():
Widget.comm.klass = Comm
ipywidgets.widgets.widget.Comm = Comm
for attr, value in _widget_attrs.items():
if value is undefined:
15 changes: 4 additions & 11 deletions ipywidgets/widgets/widget.py
Original file line number Diff line number Diff line change
@@ -456,7 +456,7 @@ def get_view_spec(self):

_view_count = Int(None, allow_none=True,
help="EXPERIMENTAL: The number of views of the model displayed in the frontend. This attribute is experimental and may change or be removed in the future. None signifies that views will not be tracked. Set this to 0 to start tracking view creation/deletion.").tag(sync=True)
comm = Instance('ipykernel.comm.Comm', allow_none=True)
comm = None

keys = List(help="The traits which are synced.")

@@ -506,16 +506,9 @@ def open(self):
args['comm_id'] = self._model_id

self.comm = Comm(**args)

@observe('comm')
def _comm_changed(self, change):
"""Called when the comm is changed."""
if change['new'] is None:
return
self._model_id = self.model_id

self.comm.on_msg(self._handle_msg)
Widget.widgets[self.model_id] = self
self._model_id = self.model_id
self.comm.on_msg(self._handle_msg)
Widget.widgets[self.model_id] = self

@property
def model_id(self):

0 comments on commit c1c34f9

Please sign in to comment.