@@ -499,36 +499,20 @@ def _get_sorteddict(self, object, dictwithhash=False, hash_method=None, hash_fil
499
499
out = object
500
500
return out
501
501
502
+ def __getstate__ (self ):
503
+ state = super (BaseTraitedSpec , self ).__getstate__ ()
504
+ inst_traits = self ._instance_traits ()
505
+ state ['__instance_traits__' ] = inst_traits
506
+ return state
507
+
508
+ def __setstate__ (self , state ):
509
+ inst_traits = state .pop ('__instance_traits__' , {})
510
+ for attr , trait in inst_traits .iteritems ():
511
+ self .add_trait (attr , trait )
512
+ super (BaseTraitedSpec , self ).__setstate__ (state )
502
513
503
514
class DynamicTraitedSpec (BaseTraitedSpec ):
504
- """ A subclass to handle dynamic traits
505
-
506
- This class is a workaround for add_traits and clone_traits not
507
- functioning well together.
508
- """
509
- def __deepcopy__ (self , memo ):
510
- """ bug in deepcopy for HasTraits results in weird cloning behavior for
511
- added traits
512
- """
513
- id_self = id (self )
514
- if id_self in memo :
515
- return memo [id_self ]
516
- dup_dict = deepcopy (self .get (), memo )
517
- # access all keys
518
- for key in self .copyable_trait_names ():
519
- _ = getattr (self , key )
520
- # clone once
521
- dup = self .clone_traits (memo = memo )
522
- for key in self .copyable_trait_names ():
523
- try :
524
- _ = getattr (dup , key )
525
- except :
526
- pass
527
- # clone twice
528
- dup = self .clone_traits (memo = memo )
529
- dup .set (** dup_dict )
530
- return dup
531
-
515
+ pass
532
516
533
517
class TraitedSpec (BaseTraitedSpec ):
534
518
""" Create a subclass with strict traits.
0 commit comments