-
Notifications
You must be signed in to change notification settings - Fork 212
Open
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels