Simplify ring.builder.RingBuilder.__deepcopy__

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
This commit is contained in:
Clay Gerrard 2015-04-23 19:39:16 -07:00
parent 43ace3c628
commit 03380380ef

View File

@ -181,9 +181,7 @@ class RingBuilder(object):
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):
"""