@@ -347,10 +347,6 @@ class PseudoMap(AutoSlots.Mixin):
347347
348348 __slots__ = ('_block' , '_ctypes' , '_active' , '_sorted' )
349349
350- # If a writer cached a repn on this block, remove it when cloning
351- # TODO: remove repn caching from the model
352- __autoslot_mappers = {'_repn' : AutoSlots .encode_as_none }
353-
354350 def __init__ (self , block , ctype , active = None , sort = False ):
355351 """
356352 TODO
@@ -577,6 +573,10 @@ class _BlockData(ActiveComponentData):
577573 """
578574 _Block_reserved_words = set ()
579575
576+ # If a writer cached a repn on this block, remove it when cloning
577+ # TODO: remove repn caching from the model
578+ __autoslot_mappers = {'_repn' : AutoSlots .encode_as_none }
579+
580580 def __init__ (self , component ):
581581 #
582582 # BLOCK DATA ELEMENTS
@@ -1348,7 +1348,7 @@ def reclassify_component_type(self, name_or_object, new_ctype,
13481348 self ._decl_order [prev ] = (self ._decl_order [prev ][0 ], idx )
13491349 self ._decl_order [idx ] = (obj , tmp )
13501350
1351- def clone (self ):
1351+ def clone (self , memo = None ):
13521352 """
13531353 TODO
13541354 """
@@ -1365,15 +1365,23 @@ def clone(self):
13651365 # NonNegativeReals, etc) that are not "owned" by any blocks and
13661366 # should be preserved as singletons.
13671367 #
1368+ pc = self .parent_component ()
1369+ if pc is self :
1370+ parent = self .parent_block ()
1371+ else :
1372+ parent = pc
1373+
1374+ if memo is None :
1375+ memo = {}
1376+ memo ['__block_scope__' ] = {id (self ): True , id (None ): False }
1377+ memo [id (parent )] = parent
1378+
13681379 with PauseGC ():
1369- new_block = copy .deepcopy (
1370- self , dict (
1371- __block_scope__ = {id (self ): True , id (None ): False },
1372- ))
1380+ new_block = copy .deepcopy (self , memo )
13731381
13741382 # We need to "detangle" the new block from the original block
13751383 # hierarchy
1376- if self . parent_component () is self :
1384+ if pc is self :
13771385 new_block ._parent = None
13781386 else :
13791387 new_block ._component = None
0 commit comments