Skip to content

Commit f2b337b

Browse files
satrachrisgorgo
authored andcommitted
fix: added back deepcopy
1 parent 54a91be commit f2b337b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

nipype/interfaces/base.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,23 @@ def __setstate__(self, state):
512512
super(BaseTraitedSpec, self).__setstate__(state)
513513

514514
class DynamicTraitedSpec(BaseTraitedSpec):
515-
pass
515+
""" A subclass to handle dynamic traits
516+
517+
This class is a workaround for add_traits and clone_traits not
518+
functioning well together.
519+
"""
520+
def __deepcopy__(self, memo):
521+
""" bug in deepcopy for HasTraits results in weird cloning behavior for
522+
added traits
523+
"""
524+
id_self = id(self)
525+
if id_self in memo:
526+
return memo[id_self]
527+
dup_dict = deepcopy(self.__getstate__(), memo)
528+
dup = self.clone_traits(memo=memo)
529+
dup.__setstate__(dup_dict)
530+
return dup
531+
516532

517533
class TraitedSpec(BaseTraitedSpec):
518534
""" Create a subclass with strict traits.

0 commit comments

Comments
 (0)