##// 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.

File last commit:

r4406:0251893c
r17238:24edb497
Show More
__init__.py
0 lines | 0 B | text/x-python | PythonLexer