Hi
Could you explain the logic behind this code:
(in traitlets.HasTraits)
def add_traits(self, **traits): """Dynamically add trait attributes to the HasTraits instance.""" self.__class__ = type(self.__class__.__name__, (self.__class__,), traits)
Why do you need to change the object class?
from ipywidgets import Box
import traitlets
b = Box()
b.class
<class 'ipywidgets.widgets.widget_box.Box'>
b.add_traits(**{'mytrait':traitlets.Unicode()})
b.class
<class 'traitlets.traitlets.Box'>
Many thanks
Hi
Could you explain the logic behind this code:
(in traitlets.HasTraits)
def add_traits(self, **traits): """Dynamically add trait attributes to the HasTraits instance.""" self.__class__ = type(self.__class__.__name__, (self.__class__,), traits)Why do you need to change the object class?
Many thanks