Skip to content

Commit 02d4bb9

Browse files
authored
Merge pull request #3591 from maartenbreddels/fix_test_traitlet_deprecated_8_port
Backport PR #3590: using _comm_default shadows possible bugs
2 parents 6330485 + e15688c commit 02d4bb9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

python/ipywidgets/ipywidgets/widgets/tests/test_set_state.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@ def deserializer(json_data, widget):
6767
return DataInstance( memoryview(json_data['data']).tobytes() if json_data else None )
6868

6969
class DataWidget(SimpleWidget):
70-
d = Instance(DataInstance).tag(sync=True, to_json=mview_serializer, from_json=deserializer)
70+
d = Instance(DataInstance, args=()).tag(sync=True, to_json=mview_serializer, from_json=deserializer)
7171

7272
# A widget that has a buffer that might be changed on reception:
7373
def truncate_deserializer(json_data, widget):
7474
return DataInstance( json_data['data'][:20].tobytes() if json_data else None )
7575

7676
class TruncateDataWidget(SimpleWidget):
77-
d = Instance(DataInstance).tag(sync=True, to_json=bytes_serializer, from_json=truncate_deserializer)
77+
d = Instance(DataInstance, args=()).tag(sync=True, to_json=bytes_serializer, from_json=truncate_deserializer)
7878

7979

8080
#

python/ipywidgets/ipywidgets/widgets/tests/utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
from ipykernel.comm import Comm
55
from ipywidgets import Widget
6+
import ipywidgets.widgets.widget
67

78
class DummyComm(Comm):
89
comm_id = 'a-b-c-d'
@@ -25,14 +26,16 @@ def close(self, *args, **kwargs):
2526
undefined = object()
2627

2728
def setup_test_comm():
28-
_widget_attrs['_comm_default'] = getattr(Widget, '_comm_default', undefined)
29-
Widget._comm_default = lambda self: DummyComm()
29+
Widget.comm.klass = DummyComm
30+
ipywidgets.widgets.widget.Comm = DummyComm
3031
_widget_attrs['_repr_mimebundle_'] = Widget._repr_mimebundle_
3132
def raise_not_implemented(*args, **kwargs):
3233
raise NotImplementedError()
3334
Widget._repr_mimebundle_ = raise_not_implemented
3435

3536
def teardown_test_comm():
37+
Widget.comm.klass = Comm
38+
ipywidgets.widgets.widget.Comm = Comm
3639
for attr, value in _widget_attrs.items():
3740
if value is undefined:
3841
delattr(Widget, attr)

0 commit comments

Comments
 (0)