From c89ec19fcaa80f47766ac6e965143d21291285f6 Mon Sep 17 00:00:00 2001 From: MinRK Date: Tue, 25 Feb 2014 14:36:46 -0800 Subject: [PATCH 1/2] don't check shape of ContainerWidget.children --- IPython/html/widgets/widget_container.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py index 528e42bac..f8661fc42 100644 --- a/IPython/html/widgets/widget_container.py +++ b/IPython/html/widgets/widget_container.py @@ -14,18 +14,27 @@ Represents a container that can be used to group other widgets. # Imports #----------------------------------------------------------------------------- from .widget import DOMWidget -from IPython.utils.traitlets import Unicode, Tuple, Instance +from IPython.utils.traitlets import Unicode, Tuple, Instance, TraitError #----------------------------------------------------------------------------- # Classes #----------------------------------------------------------------------------- + +class TupleOfDOMWidgets(Tuple): + """Like Tuple(Instance(DOMWidget)), but without checking length.""" + def validate_elements(self, obj, value): + for v in value: + if not isinstance(v, DOMWidget): + raise TraitError("Container.children must be DOMWidgets, not %r" % v) + return value + class ContainerWidget(DOMWidget): _view_name = Unicode('ContainerView', sync=True) # Keys, all private and managed by helper methods. Flexible box model # classes... - children = Tuple(Instance(DOMWidget)) - _children = Tuple(Instance(DOMWidget), sync=True) + children = TupleOfDOMWidgets() + _children = TupleOfDOMWidgets(sync=True) def _children_changed(self, name, old, new): """Validate children list. From cc1ba8b1f7dd19dc30e6844be5b73b56b41596ff Mon Sep 17 00:00:00 2001 From: MinRK Date: Tue, 25 Feb 2014 15:00:48 -0800 Subject: [PATCH 2/2] remove incorrect is instance check in children_changed --- IPython/html/widgets/widget_container.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/IPython/html/widgets/widget_container.py b/IPython/html/widgets/widget_container.py index f8661fc42..92a7f9c0f 100644 --- a/IPython/html/widgets/widget_container.py +++ b/IPython/html/widgets/widget_container.py @@ -45,7 +45,7 @@ class ContainerWidget(DOMWidget): http://www.peterbe.com/plog/uniqifiers-benchmark which provides the inspiration for using this implementation. Below I've implemented the `f5` algorithm using Python comprehensions.""" - if new is not None and isinstance(new, list): + if new is not None: seen = {} def add_item(i): seen[i.model_id] = True