Skip to content

Commit

Permalink
Simplify ring.builder.RingBuilder.__deepcopy__
Browse files Browse the repository at this point in the history
Only container classes (lists, sets, dicts, graphs, collections,
etc) need to track objects they deepcopy in the memo dict -
particularly when they may contain other containers!  As they
recreate a new container with the same items as themselves, they'll
reference the memo for each item they contain before making a
deepcopy of it, and place a reference to the copied item into memo
after they do.  Trying to help out some other container class in
this endeavor by attempting to add ourselves to the memo dict in
some useful manor on their behalf however; is not helpful.

All we need to do to make sure we're being a good __deepcopy__
implementation is make sure we pass on memo to our calls of deepcopy
so that other container classes can avoid making additional
deepcopy's of our containers if they already have a memorized copy
(which would be odd since unique instances of RingBuilders aren't
expected to share state, but hey - python doesn't have private
attributes so you never know!)

Change-Id: Ifac444dffbf79d650b2d858f6282e05d8ea741a0
  • Loading branch information
clayg committed Apr 24, 2015
1 parent 43ace3c commit 0338038
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions swift/common/ring/builder.py
Expand Up @@ -181,9 +181,7 @@ def copy_from(self, builder):
dev.setdefault("region", 1)

def __deepcopy__(self, memo):
the_copy = type(self).from_dict(deepcopy(self.to_dict(), memo))
memo[id(self)] = the_copy
return the_copy
return type(self).from_dict(deepcopy(self.to_dict(), memo))

def to_dict(self):
"""
Expand Down

0 comments on commit 0338038

Please sign in to comment.