##// END OF EJS Templates
Give subclasses of the Instance traitlet the option of overriding the klass variable to have a default klass....
Give subclasses of the Instance traitlet the option of overriding the klass variable to have a default klass. This makes it easy to construct traitlets for specific object types and default metadata. For example, we can have a traitlet for numpy arrays that gives default values for `to_json` and `from_json`: ```python def np_to_list(a): if a is not None: return a.tolist() def np_from_list(a): if a is not None: return np.array(a) class NDArray(Instance): klass = np.ndarray metadata = {'to_json': np_to_list, 'from_json': np_from_list} ``` Then the NDArray traitlet will by default have the klass and some custom metadata.
Jason Grout -
r17238:24edb497
Show More
Name Size Modified Last Commit Author
/ IPython / html / static / widgets / js
init.js Loading ...
manager.js Loading ...
widget.js Loading ...
widget_bool.js Loading ...
widget_button.js Loading ...
widget_container.js Loading ...
widget_float.js Loading ...
widget_image.js Loading ...
widget_int.js Loading ...
widget_selection.js Loading ...
widget_selectioncontainer.js Loading ...
widget_string.js Loading ...