##// 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 / nbformat
tests
v1
v2
v3
v4
__init__.py Loading ...
convert.py Loading ...
current.py Loading ...
reader.py Loading ...
sign.py Loading ...
validator.py Loading ...