You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I noticed here that there is __dict__.update() call. But in fact, this is overriding reference to previously shallow copied self.some_object_list.
def __copy__(self):
# First, let's create copies of the nested objects.
some_list_of_objects = copy.copy(self.some_list_of_objects)
some_circular_ref = copy.copy(self.some_circular_ref)
# Then, let's clone the object itself, using the prepared clones of the nested objects.
new = self.__class__(self.some_int, some_list_of_objects, some_circular_ref)
new.__dict__.update(self.__dict__) # this looks wrong as it will override reference to copied list and object with references to original list and object
# try adding this:
assert self.some_list_of_objects is not new.some_list_of_objects, "It should reference different objects"
assert self.some_circular_ref is not new.some_circular_ref, "It should reference different objects"
return new
__deepcopy__ actually is working, but still not clear why you use manual object copy and then copy __dict__. This looks redundant and basically eliminates previously copied objects. Not sure.
Activity
lufton commentedon Feb 4, 2026
The same is valid for
__deepcopy__method.lufton commentedon Feb 4, 2026
__deepcopy__actually is working, but still not clear why you use manual object copy and then copy__dict__. This looks redundant and basically eliminates previously copied objects. Not sure.