@@ -1372,6 +1372,9 @@ def __getstate__(self):
13721372 for name in self .trait_names ( type = 'delegate' ,
13731373 transient = False )
13741374 if name in dic ] ) )
1375+ # Add all instance traits
1376+ inst_traits = self ._instance_traits ()
1377+ result ['__instance_traits__' ] = inst_traits
13751378
13761379 # If this object implements ISerializable, make sure that all
13771380 # contained HasTraits objects in its persisted state also implement
@@ -1411,7 +1414,10 @@ def __setstate__ ( self, state, trait_change_notify = True ):
14111414 else :
14121415 # Otherwise, apply the Traits 3.0 restore logic:
14131416 self ._init_trait_listeners ()
1417+ inst_traits = state .pop ('__instance_traits__' , {})
14141418 self .trait_set ( trait_change_notify = trait_change_notify , ** state )
1419+ for attr in inst_traits :
1420+ self .add_trait (attr , inst_traits [attr ])
14151421 self ._post_init_trait_listeners ()
14161422 self .traits_init ()
14171423
@@ -1779,6 +1785,9 @@ def clone_traits ( self, traits = None, memo = None, copy = None,
17791785 new = self .__new__ ( self .__class__ )
17801786 memo [ id ( self ) ] = new
17811787 new ._init_trait_listeners ()
1788+ inst_traits = self ._instance_traits ()
1789+ for attr in inst_traits :
1790+ new .add_trait (attr , inst_traits [attr ])
17821791 new .copy_traits ( self , traits , memo , copy , ** metadata )
17831792 new ._post_init_trait_listeners ()
17841793 new .traits_init ()
0 commit comments