@@ -841,22 +841,33 @@ def __deepcopy__(self, memo):
841
841
return self .__clone (deepcopy = True )
842
842
843
843
def __deepcopy (self , x , memo = None ):
844
- """Deepcopy helper for the data dictionary.
844
+ """Deepcopy helper for the data dictionary or list .
845
845
846
846
Regular expressions cannot be deep copied but as they are immutable we
847
847
don't have to copy them when cloning.
848
848
"""
849
- y = {}
849
+ if not hasattr (x , 'items' ):
850
+ y , is_list , iterator = [], True , enumerate (x )
851
+ else :
852
+ y , is_list , iterator = {}, False , x .iteritems ()
853
+
850
854
if memo is None :
851
855
memo = {}
852
856
val_id = id (x )
853
857
if val_id in memo :
854
858
return memo .get (val_id )
855
859
memo [val_id ] = y
856
- for key , value in x .iteritems ():
857
- if isinstance (value , dict ) and not isinstance (value , SON ):
860
+
861
+ for key , value in iterator :
862
+ if isinstance (value , (dict , list )) and not isinstance (value , SON ):
858
863
value = self .__deepcopy (value , memo )
859
864
elif not isinstance (value , RE_TYPE ):
860
865
value = copy .deepcopy (value , memo )
861
- y [copy .deepcopy (key , memo )] = value
866
+
867
+ if is_list :
868
+ y .append (value )
869
+ else :
870
+ if not isinstance (key , RE_TYPE ):
871
+ key = copy .deepcopy (key , memo )
872
+ y [key ] = value
862
873
return y
0 commit comments