From e15688cebcd2f9370401016b216cba33bc182650 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Wed, 14 Sep 2022 20:40:57 -0600 Subject: [PATCH] Backport PR #3590: using _comm_default shadows possible bugs --- .../ipywidgets/ipywidgets/widgets/tests/test_set_state.py | 4 ++-- python/ipywidgets/ipywidgets/widgets/tests/utils.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/python/ipywidgets/ipywidgets/widgets/tests/test_set_state.py b/python/ipywidgets/ipywidgets/widgets/tests/test_set_state.py index bee5cac16a..6fc1b65aea 100644 --- a/python/ipywidgets/ipywidgets/widgets/tests/test_set_state.py +++ b/python/ipywidgets/ipywidgets/widgets/tests/test_set_state.py @@ -67,14 +67,14 @@ def deserializer(json_data, widget): return DataInstance( memoryview(json_data['data']).tobytes() if json_data else None ) class DataWidget(SimpleWidget): - d = Instance(DataInstance).tag(sync=True, to_json=mview_serializer, from_json=deserializer) + d = Instance(DataInstance, args=()).tag(sync=True, to_json=mview_serializer, from_json=deserializer) # A widget that has a buffer that might be changed on reception: def truncate_deserializer(json_data, widget): return DataInstance( json_data['data'][:20].tobytes() if json_data else None ) class TruncateDataWidget(SimpleWidget): - d = Instance(DataInstance).tag(sync=True, to_json=bytes_serializer, from_json=truncate_deserializer) + d = Instance(DataInstance, args=()).tag(sync=True, to_json=bytes_serializer, from_json=truncate_deserializer) # diff --git a/python/ipywidgets/ipywidgets/widgets/tests/utils.py b/python/ipywidgets/ipywidgets/widgets/tests/utils.py index 11a971de8a..5e7160f4eb 100644 --- a/python/ipywidgets/ipywidgets/widgets/tests/utils.py +++ b/python/ipywidgets/ipywidgets/widgets/tests/utils.py @@ -3,6 +3,7 @@ from ipykernel.comm import Comm from ipywidgets import Widget +import ipywidgets.widgets.widget class DummyComm(Comm): comm_id = 'a-b-c-d' @@ -25,14 +26,16 @@ def close(self, *args, **kwargs): undefined = object() def setup_test_comm(): - _widget_attrs['_comm_default'] = getattr(Widget, '_comm_default', undefined) - Widget._comm_default = lambda self: DummyComm() + Widget.comm.klass = DummyComm + ipywidgets.widgets.widget.Comm = DummyComm _widget_attrs['_repr_mimebundle_'] = Widget._repr_mimebundle_ def raise_not_implemented(*args, **kwargs): raise NotImplementedError() Widget._repr_mimebundle_ = 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: delattr(Widget, attr)