From c1c34f9010b40ac3374ae0c6383f64a992207ca7 Mon Sep 17 00:00:00 2001 From: "Maarten A. Breddels" Date: Thu, 29 Sep 2022 13:04:32 +0200 Subject: [PATCH] perf: no need to have Comm as a trait comm is mostly for internal use, and only causes runtime overhead. --- ipywidgets/widgets/tests/utils.py | 2 -- ipywidgets/widgets/widget.py | 15 ++++----------- 2 files changed, 4 insertions(+), 13 deletions(-) diff --git a/ipywidgets/widgets/tests/utils.py b/ipywidgets/widgets/tests/utils.py index 49bf1b41cf..33b1e23dc6 100644 --- a/ipywidgets/widgets/tests/utils.py +++ b/ipywidgets/widgets/tests/utils.py @@ -26,7 +26,6 @@ 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): @@ -34,7 +33,6 @@ def raise_not_implemented(*args, **kwargs): 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: diff --git a/ipywidgets/widgets/widget.py b/ipywidgets/widgets/widget.py index 8b8fb2d481..dfde1c79e1 100644 --- a/ipywidgets/widgets/widget.py +++ b/ipywidgets/widgets/widget.py @@ -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):